maps: a chunk large enough that its own bookkeeping stops dominating
- Commit
e3bedaaeb2e48aa7379b6c16cdef16f5992a76dd- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-28 15:01 UTC (3 months ago)
- Parents
f6e0ce3
Diff
scripts/maps/mamaps_build/src/extract.rs
diff --git a/scripts/maps/mamaps_build/src/extract.rs b/scripts/maps/mamaps_build/src/extract.rsindex f21935bb27..cdf7f72f20 100644--- a/scripts/maps/mamaps_build/src/extract.rs+++ b/scripts/maps/mamaps_build/src/extract.rs@@ -89,6 +89,14 @@ pub fn extract( coastline: Option<&Path>, spill_path: &Path, ) -> Result<(Store, Stats)> {+ // Stage A's boundaries are printed with their elapsed time so an external RSS sampler can say+ // which of them the peak belongs to. Three candidates sit within seconds of each other -- the ref+ // vector, the id index built beside it, and the node pass's per-chunk accumulators -- and+ // guessing between them has already cost more than printing them does.+ let started = std::time::Instant::now();+ let mark = |what: &str| {+ println!(" [stage A] {what} at {:.1}s", started.elapsed().as_secs_f64());+ }; let blobs = pbf::scan_blobs(input)?; let select = Select::parse(&schema::filters(layers))?; let mut stats = Stats::default();@@ -241,9 +249,12 @@ pub fn extract( for refs in members.values() { needed.extend_from_slice(refs); }+ mark("refs collected"); let table = NodeLocations::new(needed)?;+ mark("id index built, refs freed"); stats.nodes_needed = table.len() as u64; let table = resolve_nodes(input, &blobs, &blob_kinds, "Pass 3: nodes", table)?;+ mark("coordinates resolved"); // --- materialise ---------------------------------------------------------------------- //@@ -251,6 +262,7 @@ pub fn extract( // a `HashMap`'s keys, for the same reason: the output has to be reproducible and hash order is // not. The one place in this pipeline where that was a real risk, and now it is a property of // the file rather than a step that could be forgotten.+ mark("materialising"); let mut sink = Sink::create(spill_path)?; let mut reader = WayReader::open(&ways_path)?; let mut refs: Vec<i64> = Vec::new();
scripts/maps/mamaps_build/src/tiler.rs
diff --git a/scripts/maps/mamaps_build/src/tiler.rs b/scripts/maps/mamaps_build/src/tiler.rsindex fb0574be9b..f88a0eb400 100644--- a/scripts/maps/mamaps_build/src/tiler.rs+++ b/scripts/maps/mamaps_build/src/tiler.rs@@ -104,9 +104,19 @@ pub const DEFAULT_SIMPLIFICATION: f64 = 1.0; /// The size trades two costs against each other. Smaller chunks balance the pool better and give the /// reader less to get through before a worker can start; larger chunks duplicate fewer `BodyLayer` /// headers across chunks that touch the same tile, which is the whole of this design's memory-/// overhead. 64 Ki vertices is about a megabyte of `f64` pairs per chunk in flight and leaves a few-/// hundred chunks at California z14 — several tasks per core on a 64-core box.-const CHUNK_VERTICES: usize = 64 * 1024;+/// overhead.+///+/// **Raised from 64 Ki after tracing where the cost actually is.** An RSS trace of a California build+/// put stage A at 15 s under 1.6 GB and the real peak at t+256 s — 2.45 GB, deep in z13/z14 and+/// plateaued across the whole of it. That plateau is this duplication. Raising the chunk to 512 Ki+/// took the build from 325 s to 181 s and the peak from 2.45 GB to 2.19 GB: at 64 Ki there were ~3 300+/// chunks per zoom, and the allocation and merging of that many per-chunk maps dominated both `map`+/// and `encode`. 512 Ki still leaves hundreds of chunks at California z14, which is several per core+/// on a 64-core box, so the pool stays fed.+///+/// 2 Mi was measured too and was not better — 182 s and 2.21 GB, inside the noise — so this is close+/// to the floor of what the constant alone can buy.+const CHUNK_VERTICES: usize = 512 * 1024; /// Worker stack, matching [`par`]'s pool and what the toolchain gives `main` on Windows. ///