Repository navigation
Conversation
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
This was referenced Nov 21, 2026
Owner
Author
|
Colin's thoughts: low risk, high confidence, high benefit. This extends previous work to the attic. |
Owner
Author
|
Property tests: Generated by Claude Code |
Owner
Author
|
CI fuzzing (dispatched from
Generated by Claude Code |
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 #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_objectsnow usesrelation_and_way_node_membersfor 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 finalkeep_matching_skeletonsstep still picks each node's version valid at the date.localpasses 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-importsbuild ofupdate_database; see #2), warm cache, 4-core VM. The base is #18. Output is identical for every query.[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[route=hiking]; (._;>;); out count;[date:"2022-06-01T00:00:00Z"][out:csv(::count)]; rel[route=bus]; (._;>;); out count;[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel(44.60,-63.66,44.70,-63.52); (._;>;); out count;[diff:"2026-11-12T00:00:00Z","2026-11-19T00:00:00Z"]; rel(44.60,-63.66,44.70,-63.52); (._;>;); out meta;[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[type=multipolygon](44.60,-63.66,44.70,-63.52); (._;>;); out count;[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[boundary=administrative][admin_level=4][name="Nova Scotia"]; (._;>;); out count;[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)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
mmapcalls, 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
history,areas,complete, 0 differences (4 timeouts skipped). This PR against itself: 300 queries, all identical.>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>insideforeach, without meta,out idsorout skel qt. 288 returned nodes or ways. 0 differences from Collect relation node members and way nodes in one pass #18.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
localkeeps two passes. Its range restriction applies to the relations' nodes but not the ways' nodes, which a single pass can't easily reproduce.Generated by Claude Code