Repository navigation
Conversation
around compared every candidate point and segment against every point and segment of the input set, so the cost grew with (input set size) x (number of nearby candidates). An input set of 282 ways took 24 s. Index the input set's points and segments in a lat/lon grid. Each entry is filed under the cells of its reach box: its bounding box widened by its own length plus the radius. Every exact test (point near segment, segment near point, segments intersecting) can only pass when the two reach boxes overlap, so a candidate is tested only against entries in the cells its reach box touches. The exact tests are unchanged. Boxes near a pole, crossing the antimeridian or spanning more than 64 cells are never pruned: such entries are checked by every lookup, and such candidates are checked against every entry. Nova Scotia extract, after the fixed-size vector change: way(around.s0:100), 282 ways in .s0 9.9 s -> 1.2 s way(around.s0:100), ways in a city bbox >120 s -> 4.7 s way(around.s0:100), nw within 1 km 11.6 s -> 0.2 s Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
This was referenced Nov 20, 2026
Owner
Author
|
Colin's thoughts: In theory: low risk, high confidence, high benefit. This is a "slap an index on it" optimization - make it cheap to rule out certain cases to avoid doing expensive comparisons when not needed. Preventing degenerate cases helps keep the overall system healthy. However, this is high complexity to review. At least higher than most of the other PRs proposed in this work. On a few minutes of reading it, I don't understand how it works. I trust the change due to the fuzzer, but wouldn't be comfortable offering this upstream without better understanding or a lot of caveats. |
Three changes to the reach grid that narrows down which input points and segments around's exact tests look at: - An entry filed under several cells was passed to the exact test once per cell the lookup box shared with it. Each lookup now passes it once, using a stamp per entry. - When a lookup box was too large to look up cell by cell (a long candidate segment), every cell's list was scanned, so entries were tested once per cell they were filed in, up to 64 times. Such lookups now scan a list of the filed entries once. - A segment's reach box was widened by its own length plus the radius. It is now widened by the radius plus twice the most a great-circle arc of that length can bulge out of its endpoints' bounding box (L^2 tan(latitude) / 8R, a few metres for segments of some km), plus one metre. Beyond 50 km or 80 degrees of latitude the old bound is kept. The comment in around.cc gives the argument that each exact test still only passes when the two reach boxes overlap. The exact tests are unchanged, so results are the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
This was referenced Nov 21, 2026
Owner
Author
|
Clearing the human review label as there has been a new commit added |
This was referenced Nov 21, 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.
Fixes #3.
Fixes #36.
Stacked on #7 (fixed-size vectors): this PR targets that branch, so the diff shows only the grid.
Change
aroundagainst an input set compared every candidate point and segment with every point and segment of the set. The cost grew with (set size) × (nearby candidates), so modest inputs took minutes.This indexes the input set's points and segments in a coarse lat/lon grid (
Reach_Grid, 0.01° cells):Why no match can be lost. Each exact test can only pass when the two objects' reach boxes overlap (the reasoning is in a comment in
around.cc):The widening uses a 2% + 1 m margin, and the latitude nearest the pole for the longitude scale. These cases are never pruned:
Such entries are checked by every lookup, and such candidates are checked against everything.
Two files (
around.cc,around.h), about 200 lines. No change to the database format or the query API.Impact
Wall time (single-threaded, so close to CPU time) on the Nova Scotia test database (see #2). Outputs are identical in every case.
masteraroundagainst small sets (benchmark q06:node[amenity=cafe](bbox); node(around:300)[shop], and spot checks)Full text of the timed queries
A (282 ways around a point in Dartmouth, then everything within 100 m of them):
B (nodes and ways within 1 km, then ways within 100 m of them):
C (every way in a downtown Halifax bbox, then ways within 100 m of them):
Update (2026-11-21): grid revision
A second commit fixes three inefficiencies in the grid (#36), found by the degenerate-query hunt:
around.ccgives the argument that each exact test still only passes when the two boxes overlap.The exact tests are unchanged.
Impact: CPU time on this branch (#7 + this PR) with the revision. The A, B and C figures were timed separately from those above, so the comparison is rough.
[out:csv(::count)]; wr(newer:"2016-12-19T18:03:25Z")(45.574002,-62.284014,45.619842,-62.234392)->.s0; way(around.s0:20)["material"!~"^conc"]; out count;(history database, current data;.s0includes province-long road routes and rural boundaries)masterOn top of the all-changes branch (#12), the revision takes that last query from 17.9 s to 11.2 s. A dense urban query (all ways within 20 m of the highways in 44.60,-63.70,44.75,-63.45) goes from 11.2 s to 10.5 s. Most of the remaining cost of the routes query comes from how candidates are chosen for relation inputs; #38 fixes that.
Testing of the revision: done on the all-changes branch with this revision and #38, against all-changes.
Differential fuzzer:
users,complete: 1,500 queries0 differences in all three.
Targeted check: 600
aroundqueries with a single relation or way as input, at radii from 0 to 1,000 m. 0 differences.Mutation test: a build whose lookups never advance the stamp, so an entry seen once is skipped in every later lookup, was first confirmed to give wrong counts on known queries. It then differed on 158 of the 600 targeted queries, and on 3 of 1,000 fuzz queries. A mutant that only shrinks the reach boxes did not change any result. Lookups cover whole 0.01° cells (about 1 km), so reach errors of tens of metres rarely matter. This is also why the tighter bound is safe, but it means that part is checked by the argument in the comment rather than by tests.
Long-limit re-runs: the 27 queries from the degenerate-query hunt that time out or are slow on
mastergive identical output to all-changes.Memory of the revision: peak RSS for query A is 31.0 MB on this branch with the revision, and 31.1 MB on all-changes without it.
Testing
master, about 860 of them usingaroundagainst a set. 0 differences. 11 of the 12 queries that time out onmasternow finish (0.2–25 s).master(largest output 2.7 MB).mastercannot finish in 10 minutes, are identical to an exhaustive build (around: use fixed-size arrays for 3-D vectors #7 alone: the same all-pairs comparison asmaster, only faster), including a 5.5 MB output.aroundpaths.Full text of the two queries that could not be compared
Seed 3, query 2448 (differential fuzzer seed 3, query 2448):
Seed 3, query 2618 (differential fuzzer seed 3, query 2618):
These were generated by
bench/fuzz.py(bench-toolsbranch) with a vocabulary built bybench/fuzz_vocab.pyfrom the Geofabrik Nova Scotia extract of 2026-11-08. The text above is authoritative; regenerating it requires the same vocabulary.Memory
Bound: each input-set point or segment is filed in at most 64 cells, at 4 bytes per cell entry plus hash-map overhead per occupied cell. The revision adds 8 bytes per filed entry: one in the list of filed entries and one for its stamp. Larger entries go to a single always-checked list. This roughly offsets the about 120 bytes per segment that #7 saves. Overpass counts only result sets toward
[maxsize:]. Auxiliary structures, such asaround's segment lists, are not counted, and these new structures follow that convention. Counting them would change which queries fail with "Oversized", which is an observable behaviour change.Peak memory (RSS),
masteragainst all changes combined (#12):master[out:csv(::count)]; way(around:250,44.679085,-63.511161)->.s0; way(around.s0:100); out count;aroundwith a 3 km radius:[out:csv(::count)]; way(around:250,44.679085,-63.511161)->.s0; node(around.s0:3000)["amenity"]; out count;Limitations
aroundwith a relation in the input set still reads every candidate in the relation's extent (e.g.rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"];, where.s0holds long trails and boundaries; see around with a selective tag filter reads every candidate in the input set's extent first #9). The grid makes each candidate cheap, but the candidate count stays large.Generated by Claude Code