Repository navigation
Conversation
To print in id order, every out mode except qt puts one reference per element in a vector and sorts it. A reference was a pointer and the element's index, 16 bytes, or 24 when the set has attic elements, which also carried the element's timestamp. For an out of 11.5M nodes at a past date that was 277 MB. Reference each element instead by the number of its index's entry in a table of the set's non-empty vectors, current ones first, and its position in that vector: two 32-bit numbers. The index, the object and the timestamp of an attic element are read from the table and the set. The references are filled in the same order as before and sorted with the same std::sort by id, so elements with equal ids stay in the same order. Output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJTiuJPoCWZs7RtFYjm
The 8-byte references kept current and attic vectors in two tables, so every comparison in the sort branched on the kind of element. Keep one table instead, with each vector's first element (its Object part) and the size of its elements, and find an element by its position times that size. On a whole-province out ids of 12.6M current nodes this takes the sort's extra cost from about 10% of the query's CPU to about 1%, and to about 7% for 11.5M nodes at a past date. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJTiuJPoCWZs7RtFYjm
This was referenced Nov 22, 2026
cldellow
added a commit
that referenced
this pull request
Nov 23, 2026
One mutant for each of nine all-changes commits from the memory work: the past-date bbox chunking and its size check (#104), element counting in history collection (#87), the reserved and the 8-byte output references (#121, #150), in-place filtering (#130) and the Tag_Store changes (#128, #140). Each old text occurs once in all-changes at 686a701. The mutate workflow (run 45106469415, seeds 1-40) caught five: 1b30bbb, 0ec8fa9, 7b11467, f7274dc and 686a701. The other four are expected not to be caught, as their notes say: 7d39a64 and 1ef6664 change only memory, and 180c620 and 3f7cfa8 matter only for a query over [maxsize:]. Part of #145. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJTiuJPoCWZs7RtFYjm
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.
Stacked on #121 (
print-reserve-refs), which it targets: it replaces the reference vector #121 reserves. Review and merge #121 first.Fixes #149.
Change
To print in id order (every
outmode exceptqt),print.ccsorts one reference per element by id. A reference was a pointer and the element's index, 16 bytes. With attic elements it was aMaybe_Attic_Refof index, pointer and timestamp, 24 bytes.A new class
Items_By_Idinprint.ccreplaces bothcollect_items_by_idoverloads,Maybe_Attic_RefandSkeleton_Comparator_By_Id:Objectpart), the size of its elements (sizeof(Object)orsizeof(Attic< Object >)) and its index.uint32, 8 bytes. The object is at the entry's address plus position times element size, so current and attic elements are found the same way, with no branch in the sort's comparisons.Atticelement itself.timestamp()returnsNOWfor current entries, so the existing== NOWtests are unchanged.std::sortby id. Elements with equal ids therefore keep the same order.The callers,
by_id(both overloads),tags_by_idandtags_by_id_attic, read throughobj(i),idx(i)andtimestamp(i).Two commits: the first uses two typed tables and branches on the kind of element. The second merges them into one table, which removed most of the first commit's CPU cost (table below). One file,
print.cc. This doesn't change the query API, the on-disk format or[maxsize:]accounting (the references were never counted). Output is unchanged.Bound: 8 bytes per element, instead of 16 (current only) or 24 (with attic elements). Plus 16 bytes per non-empty index in the table: about 140K entries, 2.2 MB, for the whole-province node queries below.
Impact
Warm cache, 4-core cloud VM with 15 GB RAM. Outputs are byte-identical everywhere. Databases: the Geofabrik Nova Scotia extract of 2026-11-08 imported with
--meta(plain), and a Nova Scotia full-history extract (2006 to 2026-11-15) imported with--keep-atticby abetter-importsbuild (history). Both use lz4 compression.Queries
[out:csv(::id;false)]; node(42,-67.6,47.5,-58); out ids;[out:xml]; node(42,-67.6,47.5,-58); out;[out:xml]; way(42,-67.6,47.5,-58); out;[out:xml]; rel(42,-67.6,47.5,-58); out body;[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; node(42,-67.6,47.5,-58); out count;[date:"2018-01-01T00:00:00Z"][out:xml]; rel(42,-67.6,47.5,-58); out body;[date:"2012-01-01T00:00:00Z"][out:csv(::id;false)]; node(42,-67.6,47.5,-58); out ids;[date:"2021-03-01T00:00:00Z"][out:csv(::id;false)]; node(42,-67.6,47.5,-58); out ids;[date:"2018-01-01T00:00:00Z"][out:json]; way[highway](44.4,-64.0,45.0,-63.0); out geom;[date:"2018-01-01T00:00:00Z"][out:xml]; node(42,-67.6,47.5,-58); out;[date:"2018-01-01T00:00:00Z"][out:xml]; way(42,-67.6,47.5,-58); out meta;On
all-changes(at 1ef6664 plus #140), without and with this PRThis is where the large outputs peak in the output stage. RSS is one run of each under GNU time. CPU is the median of 7 alternating runs (
bench/compare.py --no-cache), for the first commit alone and for both.Against #121
CPU is the median of alternating runs (
bench/compare.py --no-cache): 5 for these queries, 7 for q01–q12, 5 for h1–h6. Peak RSS is from one extra run under GNU time (--rss).all-changestable is the more sensitive measurement.Testing
all-changes. That includes q08 and q12 (out meta), h2 ([diff:]without meta) and the attic outputs R13, R17, R18, R20, R21 and W2.upstream/master(8edf11b), seed 1, no differences:fuzzrun 45112562640: plain 1,990 same and 10 skipped,areas,complete1,999 and 1,evaluators1,998 and 2. Skipped means a timeout or resource limit, which isn't compared.historyrun 45109183663,history,users,complete: 999 same, 1 skipped.propsrun 45109203853, 60 seeds: no new failures. The 9 checks that fail also fail onupstream/master.all-changes(f7274dc and 686a701 in Mutants for the memory commits on all-changes #153) are caught by 2 and 17 property checks.Limitations
all-changes, about 0.4 s. For current-only output (P1) it is within noise.const char*over the vector's elements and casts back toconst Object*. That relies on each element'sObjectpart being at the same offset, which holds sinceAttic< Object >derives fromObjectwithout virtual bases.🤖 Generated with Claude Code
https://claude.ai/code/session_01736kJTiuJPoCWZs7RtFYjm