Repository navigation
Conversation
around's geometry for a relation in its input set is that of the relation's direct node and way members (calc_lat_lons). The candidate ranges, though, came from the relation's own index, which for a long route or a boundary is a compound index covering its whole extent: every object in that area became a candidate and had its geometry loaded and tested. calc_ranges now takes the ranges of the current relations' node members and the parent ranges of their way members, expanded by the radius as before. These cover all of the geometry the exact test uses, so results are unchanged. Attic relations keep their own index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
|
Colin thoughts: I think relations of relations aren't handled by this patch, but I believe they aren't handled by upstream, either. Low risk, high confidence, high benefit. Prevent relations from turning into degenerate queries by using a more granular set of tiles computed from their member ways/nodes rather than the bbox of the extents of the relation. Possible followup work: extend it to attic, avoid the extra calc_ranges calls. Possibly worth doing as part of this PR, will check before opening an upstream PR. |
… members The previous commit took around's candidate ranges for current relations in the input set from their members' indexes. Relations at a past date ([date:] and [diff:] queries) still contributed their own index, which for a long route or a boundary covers its whole extent. They now contribute the ranges of the members calc_lat_lons uses for their geometry: their node members and their way members as of the date. Results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
calc_ranges runs several times per execution of an around filter: for the query's candidate ranges, twice in the cheap filter, and up to four times in the exact filter. Since the previous commits, each run looked up the input relations' node and way members to compute their index ranges. On the query below, that was 6 lookups per execution and about a fifth of its run time. The member ranges depend only on which relations are in the input and on the date, so Around_Statement keeps them with those ids, the relations' timestamps at a past date, and the date, and computes them again only when one of those changes. In a foreach loop, a new input relation triggers a new lookup. On the Nova Scotia extract: [out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count; drops from 0.50 s to 0.44 s, with identical output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
|
Both follow-ups are done, as two more commits on this PR:
Testing: 3,500 fuzz queries and a 400-query targeted check, 0 differences; both mutants were caught. Details are in the description. Relations of relations are still not handled, as you noted, which matches upstream. Generated by Claude Code |
|
Removed human-reviewed label due to new commits from follow ups. |
Fixes #37.
Change
around's geometry for a relation in its input set is that of the relation's direct node and way members (calc_lat_lons). The candidate index ranges, though, came from the relation's own index. For a long route or a boundary, that's a compound index covering its whole bounding area, so every object there became a candidate and had its geometry loaded and tested.Around_Statement::calc_rangesnow uses, for current relations:These are expanded by the radius as before. They cover all the geometry the exact test uses, so results are unchanged.
Two follow-up commits:
[date:],[diff:]): they now contribute the ranges of the memberscalc_lat_lonsuses for them (node members, and way members as of the date) instead of their own index.calc_rangesruns several times per execution (6 times on the first query below: candidate ranges, the cheap filter twice, the exact filter). Each run fetched the relations' members again.Around_Statementnow keeps the member ranges, together with the date, the current relations' ids, and the past-date relations' ids and timestamps. It computes them again only when one of those changes, so aforeachloop gets a fresh lookup for each new input.Two files (
around.cc,around.h), about 80 lines across the three commits. Based on fossgismaster. No change to the database format or the query API.Impact
CPU time (user + system) on a 4-core VM with a warm cache. Output is identical in every case.
This change alone, against fossgis
master(8edf11b), on the plain database (Geofabrik Nova Scotia extract of 2026-11-08, imported with--meta):master[out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count;(from #9;.s0holds 9 relations, including a long-distance trail and boundaries)[out:csv(::count)]; rel[route=hiking](44.60,-63.66,44.70,-63.52)->.s0; node(around.s0:50)[amenity]; out count;(small relations)around, unchangedWithout the grid from #10,
aroundagainst large relation inputs still compares every candidate with every input segment (#3). Sonode(around.s0:0)with no tag filter, on the.s0above, doesn't finish in minutes with or without this PR.Together with the other
aroundchanges, on top of the all-changes branch (#12) with the grid revision of #36:[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)[out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0); out count;The first query took over 120 s (timeout) on
master, and 17.9 s on all-changes. Its cost is split between the two fixes: the grid revision takes it to 11.2 s, and this PR takes it to 3.5 s.The two follow-up commits, against this PR's first commit (5 alternating runs per build; output identical). Plain database:
[out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count;[out:csv(::count)]; rel[route=hiking](44.60,-63.66,44.70,-63.52)->.s0; node(around.s0:50)[amenity]; out count;[out:csv(::count)]; rel[route=hiking](44.60,-63.66,44.70,-63.52); foreach->.r { node(around.r:50)[amenity]; out count; }[out:csv(::count)]; way(around:250,44.679085,-63.511161)->.s0; way(around.s0:100); out count;(no relations)Full-history database (Geofabrik full-history extract of Nova Scotia, see #2):
[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count;[diff:"2018-01-01T00:00:00Z","2026-11-19T00:00:00Z"]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out ids;[date:"2022-06-01T00:00:00Z"][out:csv(::count)]; rel[route=hiking](44.60,-63.66,44.70,-63.52)->.s0; node(around.s0:50)[amenity]; out count;[out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count;(current data)Testing
The build tested was the all-changes branch plus the grid revision and this change (identical source to this commit on top of those).
Differential fuzzer (
bench/fuzz.py) against all-changes:areas,complete: 1,500 queriesusers,complete: 1,500 queries0 differences in all three. The new build against itself: 300 queries, all identical.
Targeted check: 600
aroundqueries whose input is one relation or way from the vocabulary, at radii from 0 to 1,000 m, against nodes, ways, relations andnwr, with and without tag filters. 445 had non-empty output. 0 differences.Mutation test: a build that leaves the relations' way members out of the ranges was first confirmed to give wrong counts (3,690 instead of 12,809 on the first query above). It then differed on 265 of the 600 targeted queries, and on 3 of 1,000 fuzz queries.
Long-limit re-runs: the 27 queries from the degenerate-query hunt that time out or are slow on
master(Benchmark queries and differential fuzzer #2) give identical output to all-changes, with a 900 s limit.Follow-up commits:
history,users,complete), 0 differences. The new build against itself: 300 history queries, all identical.aroundqueries with relation inputs (by id, box, tag, or mixed with ways) on the history database, at radii 0–200 m. They cover current data,[date:]and[diff:](dates 2010–2026), half of them inside aforeachwhose input relation changes each iteration. Run on the all-changes branch (All changes combined (tracking PR) #12), against all-changes before these commits: 224 non-empty, 3 timeouts skipped, 0 differences. On this branch without the grid, these queries take minutes each. Before the run was moved, 30 queries had shown 2 apparent differences, both from the first commit hitting the query's own 120 s limit and printing partial output. With a 3,000 s limit, both outputs are identical (the first commit took 411 s and 172 s, this one 132 s and 84 s).foreachloop above and on targeted queries 14, 20 and 21.Memory
Bound: the cache keeps the member ranges and the input relations' ids (4 bytes each, 12 at a past date) until the statement is destroyed. That is bounded by the input relations and their members, which
aroundloads for its geometry anyway.The first commit adds no long-lived structure. The member lookup holds the relations' direct node and way members while the ranges are computed, which is bounded by the relations' member count.
aroundloads the same members for its geometry anyway.Peak memory (RSS) drops where relations are in the input, because far fewer candidates are loaded:
#9query above (master→ this PR)[out:csv(::count)]; way(around:250,44.679085,-63.511161)->.s0; way(around.s0:100); out count;(no relations; all-changes → with both)Limitations and open questions
calc_lat_lonsstill loads the members once more for the geometry. Sharing that with the cached ranges would save another lookup per execution, at the cost of a larger change.aroundranges exceed 65,536 node tiles. The tighter member ranges can drop under that threshold, which is a loss for a query with a very selective tag at a past date. One such query ([date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count;) went from 0.36 s to 1.97 s on all-changes. Over 118 generated past-date queries on all-changes, these commits cut total CPU by 46%, with no other query slower by more than 0.6 s. Details are in All changes combined (tracking PR) #12.https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Generated by Claude Code