Repository navigation
Conversation
When make_valid repairs a multipolygon, result_combine merges each corrected ring into the result by testing it against every ring added before it with boost::geometry::intersects(). That is quadratic in the number of rings: Lake Huron (r1205151, 14233 inner rings) spends 88 of its 103 s in it. Keep the envelope of each ring alongside and skip intersects() when the envelopes are disjoint, which rules out an intersection. The rings are merged in the same order, so the output is unchanged. Adds a unit test for correct(). Lake Huron 103 s -> 25 s (-76%); Germany 43.6 s -> 39.3 s wall (-10%); planet relations phase 310 s -> 263 s (-15%). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
dktue
force-pushed
the
perf/correct-combine-boxes
branch
from
October 31, 2026 22:41
e6d6697 to
b051412
Compare
This was referenced Oct 31, 2026
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: Lake Huron, the slowest relation on the planet, 103 s → 25 s (−76%); Germany wall 43.6 → 39.3 s (−10%, three rounds); planet relations phase 310 → 263 s (−15%), with the planet total unchanged within run-to-run noise. Output identical.
When a multipolygon is invalid, tilemaker repairs it with
make_valid, i.e.geometry::correct()ininclude/geometry/correct.hpp. There,result_combinemerges each corrected ring into the result by testing it withboost::geometry::intersects()against every ring added before it. That is quadratic in the number of rings, and each test walks both rings.A few huge water and landcover relations in the planet are self-intersecting and have thousands of inner rings (islands). They dominate the relations phase, because each one runs on a single thread while the others wait. Lake Huron (r1205151, 523 outer and 14,233 inner ways) spends 88 of its 103 s in
make_valid, nearly all of it inresult_combine.This PR keeps the envelope of each ring next to it and skips
intersects()when the envelopes are disjoint, since rings with disjoint envelopes can't intersect. The rings are merged in the same order as before, so the output is unchanged. It also adds a unit test forcorrect(), which passes with and without the change.Slowest planet relations, timed on an extract with just those relations
Germany, 32 threads, three rounds each
Most of the gain is wall time: fewer threads wait at the end of the relations phase for one large relation.
Planet
Sharded
--storerun, 32 threads (one run each):The relations phase gains 47 s. The total doesn't show it, because the tile phase, which this PR doesn't touch, took 140 s longer in this run; identical planet runs vary by tens of seconds there.
Output
compare_area (per-tile area/length per layer and tag group) finds all layers identical, both for Germany and for the full tile output of the five relations above. On Germany only
poidiffers, which already differs between identical runs.Baseline for all measurements: master + #961 + #966 + #968. It changes the same file as #974 (
correct.hpp), and the two apply together cleanly.🤖 Generated with Claude Code