Repository navigation
Conversation
|
CI differences, explained: all are
Minimal case, Geofabrik Nova Scotia extract of 2026-11-08. Node 5534330612 is at 44.8697970, -63.0928802, and node 3491552732 at 44.8697971, -63.0928802, one unit (about 1 cm) north:
Cause: So this PR isn't output-neutral against current Generated by Claude Code |
68ee1e5 to
c0a46d4
Compare
|
History of the radius-0 test, from
What the history does and doesn't say:
This PR's 0.5e-7 tolerance follows the inferred intent of 8063ce8: it still absorbs rounding, which is orders of magnitude smaller, but no longer admits neighbours one unit apart, whatever the input's ways. Generated by Claude Code |
|
CI on the amended commit (c0a46d4), with the 0.5e-7 tolerance:
So these are the remaining case described above: on 555f744, a candidate inside an input way's box (relation inputs have way members) skipped the 1e-8 box test, and the 1e-7 coincidence test then matched one-unit neighbours. With the 0.5e-7 tolerance they never match. The synthetic Example ( The Generated by Claude Code |
|
Generated by Claude Code |
|
A real-data case of the radius-0 change. Geofabrik Nova Scotia extract of 2026-11-08:
Generated by Claude Code |
Since the bounding-box pre-check (f7f6d93), filter_nodes_expensive and filter_relations_expensive called matches_bboxes(lat, lon) before is_inside(lat, lon). It scanned node_bboxes, one box per input point, for every candidate node, so around against a large node set became quadratic. is_inside already finds the input points near a coordinate through radius_lat_lons, a map keyed by tile, and that test is exact. Drop matches_bboxes(lat, lon). is_inside(lat, lon) now tests the way boxes after the points and before the segments; each segment carries its way's box, so a coordinate outside every way box can't be near a segment. Also make radius 0 compare stored positions: is_inside counted points as coincident when both coordinates differed by less than 1e-7, one storage unit, so floating-point rounding let some neighbours one unit apart match. Half a unit still absorbs rounding. Without this, dropping the pre-check would have let those neighbours match again, as before f7f6d93. [out:csv(::count)]; node(44.4,-64.0,45.0,-63.0); node(around:5)[amenity]; out count; takes 17.3 s before and 2.2 s after (1.6 s before the pre-check), CPU, Geofabrik Nova Scotia extract of 2026-11-08, warm cache, 4-core VM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
c0a46d4 to
7b9c3e1
Compare
Fixes #261.
Change
Since upstream's bounding-box pre-check for
around(f7f6d93),filter_nodes_expensiveandfilter_relations_expensive(statements/around.cc) callmatches_bboxes(lat, lon)beforeis_inside(lat, lon)for each candidate node.matches_bboxes(lat, lon)scansnode_bboxes, one box per input point, and stops only at a hit. Most candidates miss, so each one scans every input box, andaroundagainst a large node set becomes quadratic.is_inside(lat, lon)already finds the input points near a coordinate throughradius_lat_lons, a map keyed by tile, and that test is exact. So:matches_bboxes(double, double)is removed, and its two callers callis_inside(lat, lon)directly.is_inside(lat, lon)tests the way boxes (way_bboxes) after the points and before the segment loop. Each segment carries its way's box (add_waypushesstd::make_pair(way_bbox, segment)), so a coordinate outside every way box can't pass the loop's own box test, and returning early gives the same answer.Radius 0 now compares stored positions.
is_inside(lat, lon)counted an input point as coincident when both coordinates differed by less than 1e-7. Coordinates are stored as integers in units of 1e-7° (::lat()isilat / 10000000 - 91.0), so neighbours one unit apart differ by about 1e-7, and floating-point rounding put some of them just below it. The tolerance is now 0.5e-7: still far above rounding error, so the same position reached by different routes still matches, but neighbours never do.The pre-check for way candidates,
matches_bboxes(const Prepared_BBox&), is unchanged. Two files, 7 lines added, 13 removed. No change to the database format or the query API.Results: the old pre-check passed a candidate inside any node box or way box, then
is_insidedecided. Now the point test runs first; the way-box test can only reject candidates the segment loop would reject.The tolerance change settles the one case where those differ. Since 8063ce8 ("Fixed a bug in around for radius zero", 2018), which replaced exact equality with
< 1e-7, nodes one storage unit apart (about 1 cm) could match each other witharound:0. The pre-check (f7f6d93) stopped that for node candidates outside every input way's box, as a side effect of its 1e-8 box tolerance, but not inside one. Without the tolerance change, this PR would have brought those matches back everywhere; the first CI run showed this (1 fuzz difference, 99propsfailures, allaround:0between one-unit neighbours; see the comment below). With it, one-unit neighbours never match, which is what the 2018 change evidently intended: tolerate rounding, not neighbours.The one remaining difference from
upstream/master555f744: a candidate inside an input way's box and one unit from an input point matched on 555f744 and doesn't here.Example, Geofabrik Nova Scotia extract of 2026-11-08 (node 5534330612 is at 44.8697970, -63.0928802; node 3491552732 one unit north, at 44.8697971):
upstream/mastera9d8f15 (before the pre-check) returns both nodes; 555f744 and this PR return 5534330612 alone.Impact
CPU time (user + system), Geofabrik Nova Scotia extract of 2026-11-08 imported with
--metaand lz4-compressed maps, warm cache, 4-core Intel Xeon VM (2.1 GHz), againstupstream/master555f744. Alternating pairs; medians and the paired ratio with 95% CI. Output identical on every query.upstream/masterOn
upstream/mastera9d8f15, before the pre-check, R6 took 1.63 s with a peak of 338 MB. The remaining peak-memory increase comes fromnode_bboxesand the boxes stored with each point, which this PR doesn't remove.[out:csv(::count)]; node(44.4,-64.0,45.0,-63.0); node(around:5)[amenity]; out count;[out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0); out count;[out:csv(::count)]; way(44.648535,-63.573386,44.662526,-63.528647)->.s0; way(around.s0:100)["created_by"!~"^JO"]; out count;[out:csv(::count)]; rel(id:5429184,7081003,8322255,9270031,10270951,13448043)->.s0; .s0 <<->.s2; way(around.s2:0)[!"height"]; out count;[out:csv(::count)]; way(around:250,44.679085,-63.511161)->.s0; way(around.s0:100); out count;[out:csv(::count)]; nw(around:1000,44.790135,-65.396762)->.s0; way(around.s0:100)["width"!="1"]; out count;[out:csv(::count)]; rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count;[out:csv(::count)]; node[amenity=cafe](44.60,-63.66,44.70,-63.52); node(around:300)[shop]; out count;[out:json][timeout:30]; (node["amenity"="school"](around:3000,44.6488,-63.5752); way["amenity"="school"](around:3000,44.6488,-63.5752); node["amenity"="kindergarten"](around:3000,44.6488,-63.5752); node["amenity"="hospital"](around:5000,44.6488,-63.5752); way["amenity"="hospital"](around:5000,44.6488,-63.5752); node["amenity"="pharmacy"](around:3000,44.6488,-63.5752); node["shop"~"supermarket|convenience|mall"](around:2000,44.6488,-63.5752); way["shop"~"supermarket|convenience|mall"](around:2000,44.6488,-63.5752); node["highway"="bus_stop"](around:1500,44.6488,-63.5752); way["leisure"="park"](around:2000,44.6488,-63.5752); way["highway"~"primary|secondary|tertiary"](around:2000,44.6488,-63.5752); way["highway"~"residential|unclassified|service"](around:500,44.6488,-63.5752); way["landuse"="industrial"](around:3000,44.6488,-63.5752); node["amenity"="fuel"](around:3000,44.6488,-63.5752); ); out center body;[out:json][timeout:45]; (node["tourism"](around:25000,44.6488,-63.5752); way["tourism"](around:25000,44.6488,-63.5752); node["amenity"~"restaurant|cafe|bar|pub|fast_food|ice_cream"](around:25000,44.6488,-63.5752); way["amenity"~"restaurant|cafe|bar|pub"](around:25000,44.6488,-63.5752); node["leisure"~"park|garden|stadium|sports_centre|marina|golf_course"](around:25000,44.6488,-63.5752); way["leisure"~"park|garden|stadium|nature_reserve"](around:25000,44.6488,-63.5752); node["historic"](around:25000,44.6488,-63.5752); way["historic"](around:25000,44.6488,-63.5752); node["natural"~"peak|beach|waterfall"](around:25000,44.6488,-63.5752); ); out body center 500;[out:json][timeout:15]; (node["amenity"~"^(restaurant|fast_food|cafe|pharmacy|school)$"](around:4828,44.6488,-63.5752); way["amenity"~"^(restaurant|fast_food|cafe|pharmacy|school)$"](around:4828,44.6488,-63.5752); node["shop"~"^(supermarket|convenience|bakery)$"](around:4828,44.6488,-63.5752); way["shop"~"^(supermarket|convenience|bakery)$"](around:4828,44.6488,-63.5752); node["leisure"~"^(park|playground|fitness_centre)$"](around:4828,44.6488,-63.5752); way["leisure"~"^(park|playground|fitness_centre)$"](around:4828,44.6488,-63.5752); relation["leisure"~"^(park|recreation_ground)$"](around:4828,44.6488,-63.5752); ); out center tags;[out:json][timeout:30]; (node["amenity"="clinic"]["name"~"dental|medical|health|family|physio",i](around:25000,44.6488,-63.5752); way["amenity"="clinic"]["name"~"dental|medical|health|family|physio",i](around:25000,44.6488,-63.5752); node["healthcare"~"dentist|physiotherapist|optometrist",i](around:25000,44.6488,-63.5752); way["healthcare"~"dentist|physiotherapist|optometrist",i](around:25000,44.6488,-63.5752); ); out body center qt;Benchmark sets, 3 pairs per query (an output check more than a timing): 21 queries on the plain database (q01–q12, p01–p06, p08–p10), sum of medians 6,922 → 6,952 ms, 1.00; 16 on the database with areas (a1–a4, t01–t11, p07), 6,826 → 6,913 ms, 1.01. All outputs identical. With 3 pairs, single queries scatter by up to ±20% (q06 1.21 here, against 1.04 at 10 pairs above).
Versions tried first:
is_insidedecides) fixed R6, but J, whose input mixes relation node members with long ways, ran into the CPU limit: it lost the way-box test.around:0, many more candidates share a tile with an input vertex than lie on one.is_inside, left J 6% slower from the repeated lookup.Testing
upstream/master555f744 on every query above (timed before the tolerance change, which doesn't affect speed), and on the fuzz query that differed in the first CI run.fuzz,historyandpropsrerun on the amended commit.Limitations
is_inside(lat, lon)is also called for each node of a candidate way. It now scans the way boxes there too before the segment loop, which costs at most one box test per input way, against one per input segment in the loop that follows.upstream/master's level (see above).https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Generated by Claude Code