Skip to content

perf: store generated points in an AppendVector - #968

Open
dktue wants to merge 1 commit into
systemed:masterfrom
dktue:perf/pointstore-append
Open

dktue wants to merge 1 commit into
systemed:masterfrom
dktue:perf/pointstore-append

Conversation

@dktue

@dktue dktue commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Gain (planet, --store): anonymous memory peak 13.10 → 11.24 GB (−14.2%), moved into reclaimable page cache. Wall time unchanged within noise; no change for in-memory runs.

Generated points (LayerAsCentroid, Layer on nodes) are kept in one std::vector<Point> per thread. On a planet that is 121.8M points × 16 bytes, all in the malloc heap: the vectors grow by doubling, so up to half of each one is unused capacity, and every reallocation briefly holds both the old and the new buffer. With --store they are also the only generated geometry store that never reaches the store files.

This PR stores them in an AppendVector<Point> instead, the container already used for the output-object index. It grows in 8192-element chunks from mmap_allocator, so there is no doubling slack or copying, and with --store the points go to the store files like the other geometry. AppendVector gets a const operator[] (covered in its unit test) so that retrievePoint can read from it. The bounds check in retrievePoint now uses >=. Before, .at() was what caught an offset equal to the size.

Planet, 32 threads, --store, openmaptiles config

Baseline = #961 + #966 (with the scaleRing fix from #941). /proc/PID/status sampled every 10 s.

before after change
anon RSS peak 13.10 GB 11.24 GB −1.86 GB (−14.2%)
file-backed RSS (store files) 143.9 GB 145.8 GB +1.9 GB (+1.3%)
wall 2471 s 2484 s +13 s (+0.5%)

The 1.9 GB moves from anonymous memory into the page cache of the store files, which the kernel can drop under memory pressure. The wall-time difference is within run-to-run noise.

Without --store, mmap_allocator uses anonymous memory, so in-memory runs see no change (Germany: RSS 8.51 vs 8.52 GB, wall 43.7 vs 43.5 s). Germany output is unchanged: same tiles and features; only poi differs, which already differs between identical runs.

The patch applies to master on its own and does not depend on #961 or #966.

🤖 Generated with Claude Code

Generated points were kept in a std::vector<Point> per thread on the
malloc heap (121.8M points on a planet), with doubling slack and copies
on every reallocation. Store them in an AppendVector instead: 8192-point
chunks from mmap_allocator, which spill to the store files with --store.
AppendVector gets a const operator[] for retrievePoint.

Planet --store anon RSS peak 13.1 GB -> 11.2 GB, wall time unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant