Skip to content

PERF: Work out each WKT area once - #156

Merged
Automation51D merged 1 commit into
mainfrom
perf/cache-wkt-areas
Sep 18, 2026
Merged

Automation51D merged 1 commit into
mainfrom
perf/cache-wkt-areas

Conversation

@YaroslavVlasenko

Copy link
Copy Markdown
Contributor

Why:

Since #152 CompareOnPremTest passes 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. MetricsOnPrem already 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

  • testWktAreaIsCached checks that a second call with the same WKT adds nothing to the cache and that getContains still follows the point. It was written first and did not compile until the cache existed.
  • CalculationsTest passes, 10 tests.
  • CompareOnPremTest on 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.

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
YaroslavVlasenko requested review from justadreamer and removed request for justadreamer September 18, 2026 17:24
@Automation51D
Automation51D merged commit 75d8519 into main Sep 18, 2026
1 check passed
@Automation51D
Automation51D deleted the perf/cache-wkt-areas branch September 18, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants