Repository navigation
Conversation
… when none are left
collect_ids looked up every tag filter in the global tag index over the
whole database, and only afterwards were the candidates narrowed to the
query's bbox, area or around ranges. Query_Statement::execute now
computes those ranges before the lookup and passes them through
progress_1 to collect_ids, which drops the candidates whose coarse index
cell lies outside them after each current-date lookup (keep_ids_inside).
filter_id_list returns at once when the candidates are already filtered
and empty, so once none are left, the remaining lookups (often a large
key such as highway) aren't read. The lookups themselves, their order and
the past-date code are unchanged.
Median CPU time on a US northeast extract, 3 alternating runs:
[out:json][timeout:90]; (way["maxheight"]["highway"](39.0,-70.0,40.0,-69.0);
way["bridge"]["maxheight"](39.0,-70.0,40.0,-69.0);
way["tunnel"]["maxheight"](39.0,-70.0,40.0,-69.0);
node["maxheight"]["highway"](39.0,-70.0,40.0,-69.0); ); out center;
0.24 s -> 0.01 s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJWpJaGbt8ML6jz9N35
cldellow
force-pushed
the
tag-lookup-drop-outside
branch
from
December 2, 2026 20:14
9457032 to
695c17f
Compare
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.
Part of #242. A smaller cut of #243: its first step on its own.
Change
collect_ids(data/tags_global_reader.h) looks up every tag filter in the global tag index over the whole database, and only afterwards are the candidates narrowed to the query's bbox, area oraroundranges. With this change:query.cc:Query_Statement::executecomputes each element type's constraint ranges just before its tag lookup instead of after it, and passes them throughprogress_1tocollect_ids(no ranges when they are global). This is a move: the laterintersect_rangessteps stay where they were.collect_idscallskeep_ids_inside, which drops the candidates whose coarse index cell (a multiple of 0x100) lies outside those ranges. It merges the ranges with the existingRanges::sort.filter_id_listreturns at once when the candidates are already filtered and empty (2 lines), so once none are left, the remaining lookups (often a large key such ashighway) aren't read at all.Two files, +49 −24, against #243's +176 −41. No change to the database format or the query API.
Relation to #243
#243 does three things: (A) this change, (B) the smallest lookup first, by block count (
Block_Backend::count_blocks), and (C) checking the remaining tags late when that reads fewer blocks (count_late_check_blocks). This PR is A alone, written as small as it could be (an earlier version of this PR took #243's code for A verbatim, at +86 −39). B and C would be a follow-up on top of it:count_blocks, and the four current-date lookup loops turned into one sorted loop with the late-check cutoff. #243 itself would need rewriting on top of this version rather than applying as is.Impact
US northeast extract (full history, LZ4), warm cache, 4-core 2.1 GHz Xeon VM. Median CPU (user + system) of
osm3s_queryover 3 alternating runs per build pair;upstream/masteris a7ff7ab. Peak RSS ismaster/ A / #243. The A column was measured with the first version of this PR; the current, smaller version gives the same results (see below the table).mastermasteragainst A) on the queries the table shows as slower: p15 1.003 (95% CI 0.995–1.012), p07 1.009 (0.999–1.019) and p03 1.002 (0.993–1.010) are noise; p06 0.980 (0.967–0.994) is 2% faster; p04 is 1% slower, 1.010 (1.003–1.017), faster in 4 of 25 pairs. p04 unions 13 statements in a 0.4° box: each computes its ranges earlier and filters after each key-value lookup without dropping much. query: drop tag-index candidates outside the query's ranges during the lookup #243 shows the same (1.02).way["maxheight"]["highway"](bbox); out center;); total CPU 52.5 s against 52.9 s over 3 alternating runs. Re-run as 25 pairs, the three largest differences are noise or close to it: dense 1° 1.023 (95% CI 1.000–1.046), p13 0.952 (0.897–1.011), sparse 0.99999° 0.980 (0.927–1.036).Queries
dense_099
dense_1
empty_099
empty_1
sparse_099
sparse_1
p01_maxheight_bbox1deg
p02_amenities_around_union
p03_admin_in_area
p04_brands_bbox_ci
p05_global_data_center
p06_food_around_regex
p07_global_seamark_recurse
p08_global_cameras
p09_3d_buildings_bbox
p10_tourism_around25k
p11_brownfield_bigbbox
p12_clinic_name_ci_around25k
p13_map_call_meta
p14_area_by_name_worship
p15_tiny_bbox_many_keys_geom
p16_hgv_restrictions_bbox
p17_anchored_regex_around
p18_fuel_bigbbox
p19_venues_bbox_name_ci
p20_office_around25k
Testing
masteron all 26 queries, for the first version and for query: drop tag-index candidates outside the query's ranges during the lookup #243; this version's output is byte-identical to the first version's on those and on the six single-statement queries.Limitations
Generated by Claude Code