Repository navigation
Conversation
Id_Predicate checks every object it is shown with std::binary_search over the sorted id list. Most objects it sees are not in the list: a tag query such as node[amenity=restaurant] finds the matching ids in the tag index, then reads every node block of each quadtile that holds one of them and tests each node against the ids. Add a small hashed bit filter (about 16 bits per id, at most 16 MiB) that rejects most absent ids with one bit test; the binary search still decides every id the filter lets through, so results do not change. Collect_Items now builds its predicate once instead of once per chunk. On a Nova Scotia extract (12.6M nodes), median CPU time per query with warm caches: nwr[amenity=restaurant] 160 ms -> 124 ms node[natural=peak] 183 ms -> 129 ms rel boundary with (._;>>;) 682 ms -> 571 ms Outputs are byte-identical. No change to the database format or the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Owner
Author
|
Colin's thoughts: low risk, high confidence, high benefit. Use a lossy hashmap to bail early before paying for an expensive binary search. |
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 #6.
Change
Id_Predicatechecks each candidate object withstd::binary_searchover a sorted id list. Most candidates are not in the list: a tag query such asnwr[amenity=restaurant]gets the matching ids from the tag index, then decompresses every node block of each quadtile holding one of them and tests every node in those blocks.This adds a small hashed bit filter in front of the binary search:
Collect_Itemsbuilds its predicate once instead of once per chunk.There is no change to the database format or the query API. Two files changed, about 60 lines.
Impact
Median CPU time (user + system) of
osm3s_query, 7 runs per build, with warm page cache. The data is the Geofabrik Nova Scotia extract of 2026-11-08 (12.6M nodes, 882k ways, 20.6k relations), imported with--meta. The baseline ismaster(8edf11b). Output is byte-identical to the baseline for every query.The queries and the harness (
bench/compare.py) are on thebench-toolsbranch; the queries are described in #2.Default compression (LZ4 on
.binfiles,.mapfiles uncompressed):nwr[amenity=restaurant]node[natural=peak](._;>;)(._;>>;)out geomWith
nodes.binandways.binuncompressed (all other files LZ4): decompression drops out, so the id check is a larger share of what is left.The queries that hardly use the id check (bbox scans,
out geom,out meta,around) change by 6% or less, and they dominate the totals.Profile of q01 on the LZ4 database:
binary_searchfalls from 36% of samples to 4%, while the filter adds about 7%. LZ4 decompression rises from 43% to 66% and is now the main cost.Benchmark queries (from
bench/queries/on thebench-toolsbranch)[out:csv(::count)]; nwr[amenity=restaurant]; out count;[out:csv(::count)]; node[natural=peak]; out count;[out:csv(::count)]; node(44.60,-63.66,44.70,-63.52); out count;[out:csv(::count)]; way[highway](44.60,-63.66,44.70,-63.52); out count;[out:csv(::count)]; way[highway=motorway]; (._;>;); out count;[out:csv(::count)]; node[amenity=cafe](44.60,-63.66,44.70,-63.52); node(around:300)[shop]; out count;[out:csv(::count)]; rel[boundary=administrative][admin_level=4][name="Nova Scotia"]; (._;>>;); out count;[out:xml]; nwr[amenity](44.60,-63.66,44.70,-63.52); out meta;[out:json]; way[building](44.640,-63.585,44.655,-63.565); out geom;[out:json]; way[highway](44.60,-63.66,44.70,-63.52); out geom;[out:csv(::count)]; node[highway=traffic_signals](44.60,-63.66,44.70,-63.52); way(bn); rel(bw); out count;Bounding boxes are in Halifax, Nova Scotia; q07 names the Nova Scotia province boundary.
Testing
master(bench/fuzz.py, seed 2; see Benchmark queries and differential fuzzer #2). 2,997 identical, 3 skipped (timeouts), 0 differences.arounduses the id check to fetch way nodes).complete). That covered 10,000 queries across the plain, area and history databases (6,000 / 2,000 / 2,000), with 0 differences. The first fuzz run above predates a fuzzer fix: about 8% of its queries were invalid on both builds (see Benchmark queries and differential fuzzer #2).Memory
Bound: the filter uses about 2 bytes per id (16 bits), capped at 16 MiB per predicate, alongside the id list's own 8 bytes per id. Overpass counts only result sets toward
[maxsize:]. Auxiliary structures, such as the id list this filter sits in front of oraround'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), Nova Scotia test database,
masteragainst this change combined with the others in #12:masternwr[amenity=restaurant])(._;>>;))[out:csv(::count)]; way[highway]->.w; node(w.w); out count;The 2.8M-id query shows no change. It may not use
Id_Predicate, or the filter's allocation may not coincide with the peak; that hasn't been traced.Limitations and open questions
.idxheader would tell us (od -An -tu2 -j6 -N2 nodes.bin.idx: 0 = none, 1 = zlib, 2 = LZ4).[maxsize:]. It is at most 16 MiB per predicate, and most queries use a few KB. A lower cap, or reporting the allocation toResource_Manager, would close this gap.binary_searchwould be a good addition.https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Generated by Claude Code