Repository navigation
Conversation
…gons twice systemed#949 made profiles with many huge polygons 52% slower: rect_clip ran the Liang-Barsky computation for every segment of the whole polygon on every tile, and the polygon was loaded from the store a second time because fast_clip had modified the first copy. - clipRing rejects a segment whose end points both lie beyond the same box edge with four comparisons, before the clip computation - a valid polygon over 1,000 points is kept for rect_clip; fast_clip works on a copy instead of the moved original parks profile, Alaska/BC/Yukon, 16 threads: 275.6 -> 210.2 s (-24%), CPU -26%. Output identical (parks extract, Germany OpenMapTiles). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Gain: profiles with many huge polygons get 24% faster (−26% CPU): a
parksprofile on Alaska/BC/Yukon goes from 275.6 to 210.2 s, recovering about 70% of what #949 cost it. Planet (OpenMapTiles): wall time unchanged, 4.5% less CPU. Output identical.#949 made this profile 52% slower: cldellow's
parksslice is almost entirely huge forest and park polygons. A bisect on Alaska/BC/Yukon (16 threads, 2 rounds) put the step exactly at #949:The profile showed two costs, both proportional to the size of the whole polygon, paid for every tile it covers:
rect_clipran the full Liang-Barsky computation for every segment (four divisions plus branching), also for segments far away from the tile. For a polygon with hundreds of thousands of points in a z14 tile, that is almost all of them.clipSegmentwas 91% ofrect_clip's time.fast_clip, which modifies it, sorect_clipneeded the original again.This PR fixes both:
clipRingrejects segments beyond one edge first. If both end points lie beyond the same edge of the box (both left, right, above or below), the segment can't reach the box: four comparisons instead of the clip computation.rect_clipinstead of loaded again. For polygons over 1,000 points known to be valid,fast_clipworks on a copy. Smaller polygons keep the existing path, so they don't pay for a copy they rarely need.Profile,
parkson Alaska/BC/Yukon, 16 threads (CPU samples)populateMultiPolygonrect_clipResults, 16 threads, 2 rounds each
parks, Alaska/BC/Yukon, wallPlanet, OpenMapTiles profile,
.pmtiles, 32 threads,--store --fast(one run each)On the planet the OpenMapTiles profile has few polygons big enough to matter here, so the wall time doesn't change. The output was 48 MB (0.06%) smaller; planet runs differ slightly between identical runs, and the Germany and
parkscomparisons below are identical.Output
parkson Alaska/BC/Yukon: identical (compare_area: no differing polygon, line or point groups).poidiffers, which already differs between identical runs.rect_cliptests from perf: exact rectangle clip for valid polygons (planet 25% faster, 31% less CPU) #949.The remaining distance to the pre-#949 time comes from clipping the whole polygon for every tile. Since #939, the clip cache is per batch, so huge polygons are rarely clipped from a smaller cached piece; that also costs this profile about 2.8× compared with before #939. A deterministic shared cache is a separate, larger change.
🤖 Generated with Claude Code