Skip to content

Collect relation node members and way nodes in one pass at past dates - #95

Open
cldellow wants to merge 1 commit into
single-pass-member-nodesfrom
single-pass-member-nodes-attic
Open

cldellow wants to merge 1 commit into
single-pass-member-nodesfrom
single-pass-member-nodes-attic

Conversation

@cldellow

Copy link
Copy Markdown
Owner

Fixes #94.

Stacked on #18 (the single pass for current data): this PR targets that branch, so the diff shows only the extension to past dates.

Change

Down recursion (>) over relations collected the relations' node members and the ways' nodes in two separate passes over the node blocks, then took the union. #18 merged them into one pass for current data. At a past date ([date:], or the old side of [diff:]), both passes still ran, and each read the current and attic node files plus the current and attic node metadata that attic queries use to check versions.

add_nw_member_objects now uses relation_and_way_node_members for dates too. That function already handles attic relations and ways. It merges the two id lists and the two range sets, then reads the node blocks once. The relations' ways are still collected first, as before, and the final keep_matching_skeletons step still picks each node's version valid at the date.

local passes a range restriction, so it keeps the two passes, as in #18.

One file, 11 lines added and 4 removed. No change to the database format or the query API.

Impact

CPU time (user + system), median of 5 alternating runs per build, Nova Scotia history database (Geofabrik full-history extract, imported with a better-imports build of update_database; see #2), warm cache, 4-core VM. The base is #18. Output is identical for every query.

Query #18 This PR Change
[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[route=hiking]; (._;>;); out count; 1,780 ms 1,130 ms −37%
[date:"2022-06-01T00:00:00Z"][out:csv(::count)]; rel[route=bus]; (._;>;); out count; 1,350 ms 1,010 ms −25%
[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel(44.60,-63.66,44.70,-63.52); (._;>;); out count; 1,970 ms 1,760 ms −11%
[diff:"2026-11-12T00:00:00Z","2026-11-19T00:00:00Z"]; rel(44.60,-63.66,44.70,-63.52); (._;>;); out meta; 7,330 ms 6,830 ms −7%
[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[type=multipolygon](44.60,-63.66,44.70,-63.52); (._;>;); out count; 900 ms 880 ms −2% (noise)
[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[boundary=administrative][admin_level=4][name="Nova Scotia"]; (._;>;); out count; 100 ms 100 ms unchanged
[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; way[highway=primary](44.60,-63.66,44.70,-63.52); (._;>;); out count; (history benchmark h4: ways only, not affected) 340 ms 330 ms unchanged

Route relations gain most: they have few node members, but those are spread out. For the hiking query, the relations' pass alone read 773 node blocks and 1,640 node metadata blocks. For that query, counting block reads by tracing mmap calls, node block reads (current and attic) drop from 1,552 to 780, which is exactly the number of distinct blocks. Node metadata block reads drop from 1,655 to 192.

Current-data queries take the #18 path and are not affected.

Testing

  • Differential fuzzer against Collect relation node members and way nodes in one pass #18, history database: 2,500 queries with history,areas,complete, 0 differences (4 timeouts skipped). This PR against itself: 300 queries, all identical.
  • Targeted check: 400 queries running > at a past date (80% [date:], 20% [diff:], dates from 2010 to 2026) on relations chosen by box, by tag, by id, or mixed with ways and nodes. The shapes are (._;>;), >, > on a named set, and > inside foreach, with out meta, out ids or out skel qt. 288 returned nodes or ways. 0 differences from Collect relation node members and way nodes in one pass #18.
  • Mutation test: a build that drops the attic relations' node members from the merged pass. The targeted check caught it on 87 of the 400 queries, so the check exercises relations that changed after the date.

Memory

The merged id list and range set live during the pass, as in #18: 8 bytes per node id. Two result sets are no longer built and merged. Peak RSS is unchanged within 0.6 MB for every query above (hiking: 65.6 → 65.7 MB).

Limitations

  • local keeps two passes. Its range restriction applies to the relations' nodes but not the ways' nodes, which a single pass can't easily reproduce.
  • Narrow test setup: one regional extract, warm cache, one VM.

Generated by Claude Code

Down recursion (>) over relations collected the relations' node members and
the ways' nodes in two separate passes over the node blocks, then took the
union. The current-data case already does it in one pass. At a past date
([date:], or the old side of [diff:]), it still read every node block twice,
current and attic files, and both passes also read the node metadata that
attic queries use to check versions.

add_nw_member_objects now uses relation_and_way_node_members, which handles
attic relations and ways, for dates too, unless a range restriction is given
(local). It merges the two id lists and the two range sets, then reads the
node blocks once. The final keep_matching_skeletons step picks the version
valid at the date, as before.

On the Nova Scotia history database:

  [date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[route=hiking]; (._;>;); out count;

drops from 1.78 s to 1.13 s, with identical output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
@cldellow cldellow added the query-perf Query performance change; collected on all-changes label Nov 21, 2026 — with Claude
@cldellow cldellow added the human-reviewed Colin has reviewed this. label Nov 21, 2026
@cldellow

Copy link
Copy Markdown
Owner Author

Colin's thoughts: low risk, high confidence, high benefit.

This extends previous work to the attic.

Copy link
Copy Markdown
Owner Author

Property tests: bench/props/props.py (seeds 1-60, with history) passed against upstream/master at this branch's merge base, dispatched by hand because this PR doesn't target master: https://github.com/cldellow/Overpass-API/actions/runs/45042998570


Generated by Claude Code

Copy link
Copy Markdown
Owner Author

CI fuzzing (dispatched from master), against upstream/master at 8edf11b, seed 1, on this PR's head (321de47):

  • fuzz (plain database, plain and areas,complete): run 45108129220, 4,000 queries: 3,989 same, 11 skipped, 0 differences.
  • history (full-history database, history,users,complete): run 45108135902, 1,000 queries: 999 same, 1 skipped, 0 differences.

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-reviewed Colin has reviewed this. query-perf Query performance change; collected on all-changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants