Skip to content

Tag_Store: keep only a chunk's ids when printing in chunks - #140

Open
cldellow wants to merge 1 commit into
tag-store-ids-oncefrom
tag-store-chunk-ids
Open

cldellow wants to merge 1 commit into
tag-store-ids-oncefrom
tag-store-chunk-ids

Conversation

@cldellow

@cldellow cldellow commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #128 (tag-store-ids-once), which it targets: it replaces the lines #128 changed in prefetch_chunk. Review and merge #128 first.

Fixes #139.

Change

out with tags prints large sets in chunks of 1M nodes or 512K ways or relations, in id order, and Tag_Store::prefetch_chunk collects each chunk's tags. It kept the ids of the whole set, per coarse index, and filtered them by the chunk's id bounds while collecting. Now both overloads (current and attic) clear the lists and generate them per chunk, from the elements whose ids are within [lower_id_bound, upper_id_bound). Two new overloads of generate_ids_by_coarse (core/type_tags.h) take the bounds. They also skip the second, redundant sort of the existing ones. The bounds checks already in collect_tags_framed and the framed collect_attic_tags stay. They are now redundant but harmless.

A side effect: each chunk's tag range query covers only the coarse indices that have elements in that chunk.

Two files, 61 lines added and 8 removed. This doesn't change the query API, the on-disk format or [maxsize:] accounting (the tag store was never counted). Output is unchanged.

Bound: the lists hold at most one chunk's ids: 1M × 8 bytes for nodes, 512K × 16 bytes for attic ways or relations. Cost: one pass over the set per chunk to pick out the chunk's ids.

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-attic by a better-imports build (history). Both use lz4 compression.

Queries

Name Database Query
P2 plain [out:xml]; node(42,-67.6,47.5,-58); out;
W1 plain [out:xml]; way(42,-67.6,47.5,-58); out;
R2 plain [out:json]; way[highway]; out geom;
R3 plain [out:xml]; rel(42,-67.6,47.5,-58); out body;
R4 plain [out:json]; nwr[name]; out center;
R21 history [date:"2018-01-01T00:00:00Z"][out:xml]; node(42,-67.6,47.5,-58); out;
W2 history [date:"2018-01-01T00:00:00Z"][out:xml]; way(42,-67.6,47.5,-58); out meta;
R9 history [date:"2018-01-01T00:00:00Z"][out:json]; way[highway]; out geom;
R10 history [date:"2018-01-01T00:00:00Z"][out:json]; nwr[name]; out center;
R13 history [date:"2018-01-01T00:00:00Z"][out:xml]; rel(42,-67.6,47.5,-58); out body;

Against #128

CPU is the median of alternating runs (bench/compare.py --no-cache): 7 for P2 and W1, 5 for the other plain queries, 3 for history. Peak RSS is from one extra run under GNU time (--rss).

Query CPU #128 CPU this PR RSS #128 RSS this PR
P2 16.14 s 16.64 s (×1.03) 696.8 MB 603.0 MB
R21 33.87 s 29.28 s (×0.86) 1,241.6 MB 1,241.3 MB
W1 10.59 s 10.34 s 1,092.9 MB 1,093.2 MB
R2 4.95 s 4.80 s 287.2 MB 287.4 MB
R3 1.98 s 1.94 s 329.5 MB 329.9 MB
R4 3.99 s 4.18 s 262.3 MB 262.3 MB
W2 35.58 s 35.40 s 690.1 MB 690.3 MB
R9 13.52 s 13.44 s 235.9 MB 236.1 MB
R10 24.05 s 23.90 s 265.8 MB 265.8 MB
R13 16.00 s 15.35 s 324.1 MB 324.4 MB

Benchmark queries q01–q12 (7 runs): total CPU 2,449 → 2,445 ms (×1.00), RSS within 0.3 MB on each. History benchmark h1–h6 (5 runs): total ×1.03, RSS within 0.3 MB on each; none of them prints more than one chunk, so this is noise. The queries are defined in #2 and #12.

On all-changes (at 1ef6664, which includes #128), without and with this commit

One run of each under GNU time.

Query CPU before CPU after RSS before RSS after
P2 8.66 s 8.44 s 637.4 MB 537.0 MB
R21 14.34 s 13.38 s 594.9 MB 518.3 MB
W1 6.06 s 6.34 s 465.5 MB 464.2 MB
R2 2.76 s 2.64 s 176.1 MB 176.6 MB
R3 1.54 s 1.63 s 198.4 MB 199.1 MB
R4 3.49 s 3.26 s 204.3 MB 204.8 MB
W2 12.87 s 13.18 s 454.6 MB 454.3 MB
R9 5.35 s 4.94 s 145.0 MB 145.4 MB
R10 8.83 s 9.90 s 210.7 MB 211.0 MB
R13 5.66 s 5.95 s 200.1 MB 200.7 MB

Testing

Limitations

  • The extra pass per chunk could be avoided by taking the chunk's ids from the id-sorted references print.cc already holds. That would need a different prefetch_chunk signature, so it isn't done here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01736kJTiuJPoCWZs7RtFYjm

Chunked output (tags_by_id, tags_by_id_attic) prints 1M nodes or 512k
ways or relations at a time, and prefetch_chunk loads only that chunk's
tags. It still kept the ids of the whole set, per coarse index, and
filtered them by the chunk's id bounds while collecting. On a whole-
province `out` of 12.6M nodes these lists were 145 MB of the peak.

Generate them per chunk from the elements within the bounds instead.
They then hold at most one chunk's ids, and the tag range query covers
only the coarse indices that have elements in the chunk. Output is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJTiuJPoCWZs7RtFYjm
@cldellow cldellow added the query-memory label Nov 22, 2026 — with Claude
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants