PERF: Work out each WKT area once - #156
Merged
Merged
Conversation
Introduced a caching mechanism to store pre-computed areas for WKT strings, ensuring each area is calculated only once. Added tests to verify caching behavior and maintain functionality consistency. This change reduces redundant computations, enhancing overall efficiency.
YaroslavVlasenko
requested review from
justadreamer
and removed request for
justadreamer
September 18, 2026 17:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why:
Since #152
CompareOnPremTestpasses on the current Enterprise data file, but it takes 1064 s on CI where it took 16 s on the previous file, and every nightly leg in this repository and in ip-intelligence-java pays for it. The compare example measured the area for every truth IP from scratch, and many IPs resolve to the same area: on an archived copy of the September file the 24597 distinct truth IPs resolve to 3696 distinct areas, the largest with over 100000 characters of WKT.Calculations.getAreas(wkt, ...)now keeps the parsed geometry and its area per WKT string, so each distinct area is measured once. Whether the point lies inside is still worked out per call.MetricsOnPremalready kept its own per-WKT map and is left as it is.This is the Java side of 51Degrees/ip-intelligence-dotnet-examples#394.
Tests
testWktAreaIsCachedchecks that a second call with the same WKT adds nothing to the cache and thatgetContainsstill follows the point. It was written first and did not compile until the cache existed.CalculationsTestpasses, 10 tests.CompareOnPremTeston the archived September file: 37.6 s locally, where the previous run on the same file went over the 10 minute local limit. CI is the check for the full leg.