Skip to content

tag filters at a past date: don't add every candidate to the timestamp map - #237

Open
cldellow wants to merge 1 commit into
masterfrom
attic-regex-ids-find
Open

cldellow wants to merge 1 commit into
masterfrom
attic-regex-ids-find

Conversation

@cldellow

Copy link
Copy Markdown
Owner

Fixes #236.

Change

  • Tag_Entry_Listener_Value_Regex::filter_ids (data/filter_ids_by_tags.h) looks candidates up with find() instead of operator[]. A candidate absent from the map has no matching tag entry and is rejected, as the zero-initialised entry operator[] created was.

One file, 2 lines changed. No change to the database format, the query API or the results.

Impact

Mostly CPU. The map lives for one cell at a time, so peak memory doesn't move.

US northeast full-history extract (Geofabrik), warm cache, 4-core VM. Builds run alternately; peak RSS and median user+sys CPU of 3 runs per query. Run-to-run CPU noise is about ±4% per query. Base is upstream/master a9d8f15.

Query peak, base peak, this PR change CPU, base CPU, this PR change
d1 509 MB 508 MB -0% 16.68 s 15.36 s -8%
d2 231 MB 231 MB +0% 6.78 s 6.58 s -3%
d3 66 MB 66 MB -0% 9.60 s 9.71 s +1%
d4 220 MB 220 MB -0% 7.34 s 6.66 s -9%
h2 166 MB 166 MB -0% 4.76 s 5.11 s +7%
h8 544 MB 544 MB -0% 8.75 s 8.33 s -5%
m3 105 MB 105 MB +0% 2.73 s 2.81 s +3%
CPU total 56.6 s 54.6 s -3.7%

Instruction counts (valgrind callgrind; these repeat exactly between runs). They are smaller than the wall-time gains: the saved work is mostly allocation and cache misses, which instruction counts underweight.

Query base this PR change
s_d1_adiff_small 12.462 G 12.219 G -1.95%
s_d4_diff_convert_small 17.678 G 17.543 G -0.76%
s_m3_attic_meta_small 4.109 G 4.102 G -0.17%

On all-changes the same change took total CPU over the 7 queries from 43.7 to 39.6 s (d1 −20%, d4 −16%), on a run where the machine also built another tree, so treat that as indicative.

Queries

d1 (adiff amenity buildings)

[adiff:"2025-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; (node["amenity"](42.2,-71.3,42.5,-70.9); way["building"](42.3,-71.15,42.4,-71.0); ); out geom;

d2 (diff highways)

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; way["highway"](42.3,-71.2,42.4,-71.0); out geom;

d3 (adiff routes)

[adiff:"2025-06-01T00:00:00Z","2026-11-01T00:00:00Z"]; relation["route"="bus"](42.2,-71.3,42.5,-70.9); out geom;

d4 (diff convert)

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; nwr["amenity"](42.3,-71.2,42.4,-71.0); convert item ::id=id(), name=t["name"], amenity=t["amenity"]; out;

h2 (attic way geom)

[date:"2020-01-01T00:00:00Z"]; way(42.30,-71.15,42.40,-71.00); out geom;

h8 (attic amenity meta)

[date:"2018-06-01T00:00:00Z"]; (node["amenity"](42.2,-71.3,42.5,-70.9); way["amenity"](42.2,-71.3,42.5,-70.9);); out meta;

m3 (attic meta highways)

[date:"2022-01-01T00:00:00Z"]; way["highway"](42.3,-71.2,42.4,-71.0); out meta;

s_d1_adiff_small (d1 adiff small)

[adiff:"2025-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; (node["amenity"](42.34,-71.10,42.37,-71.04); way["building"](42.35,-71.07,42.36,-71.05); ); out geom;

s_d4_diff_convert_small (d4 diff convert small)

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; nwr["amenity"](42.34,-71.08,42.36,-71.05); convert item ::id=id(), name=t["name"], amenity=t["amenity"]; out;

s_m3_attic_meta_small (m3 attic meta small)

[date:"2022-01-01T00:00:00Z"]; way["highway"](42.34,-71.08,42.36,-71.05); out meta;

Testing

  • Byte-identical output to upstream/master on all 7 queries above.
  • CI: fuzz, history and props run on this PR.

Limitations and open questions

  • eval_id in the same listener and in Tag_Entry_Listener_Key_Regex still insert with operator[], but only for tag entries of the wanted key, which is what the map is for.


Generated by Claude Code

…p map

Tag_Entry_Listener_Value_Regex::filter_ids keeps the candidates whose
tag matched at the requested date. It looked each candidate up with
timestamps[*it], and operator[] inserts a map entry for every candidate
without a matching tag entry, only to reject it. For a cell of a common
key that is a node allocation per candidate.

It now uses find(); a candidate absent from the map is rejected as before.

On a US northeast full-history extract (Geofabrik), warm cache, 4-core VM,
median CPU of 3 alternating runs:

  [adiff:"2025-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; (node["amenity"](42.2,-71.3,42.5,-70.9); way["building"](42.3,-71.15,42.4,-71.0); ); out geom;
      16.68 s -> 15.36 s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJWpJaGbt8ML6jz9N35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

query-perf Query performance change; collected on all-changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Past-date tag filters add every candidate to a map just to reject it

2 participants