Repository navigation
Conversation
coalesce_features() grouped features by property hash in a HashMap and emitted the groups in iteration order. std's HashMap is seeded per map, so the order of coalesced features in a tile, and therefore the archive bytes, changed from run to run. Groups now keep the order in which their first feature appears, which is the Morton order the tile was sorted in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tiles are always gzipped at the fast level 1. A new gzip_level option (0-9) in R and Python freestile(), and TileConfig::gzip_level in the core, sets the level for the in-memory pipeline. None keeps level 1, so existing output is unchanged; other levels change only the compression, never the decompressed tiles. Out-of-range levels are refused before any output is written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
freestile() with several layers held every layer's features, and every layer's per-zoom tile assignment, in memory at once. LayeredTiler tiles each layer on its own, spools its raw per-tile encodings to a temporary file with a small (tile, layer) index, and at the end concatenates each tile's layer encodings in layer order and gzips them. MVT and MLT tiles are sequences of independently encoded layers, and every per-layer step (clipping, snapping, dropping, clustering, coalescing, feature order) depends only on that layer, so the archive is byte-identical to generate_pmtiles(). R and Python freestile() use it for every multi-layer call. Python's new freestile_layers() also loads layers lazily from (name, source) pairs, where a source is a GeoDataFrame, a FreestileLayer, a GeoParquet path or a callable (walkerke#17). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 13, 2026
This branch has not been deployed
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 #31 and #32: please review those first. Once they merge, this PR's diff is the last commit only.
Multi-layer
freestile()calls hold every layer in memory for the whole run: all decoded features, and at each zoom every layer's tile assignment. This is the memory problem reported in #17. This PR tiles one layer at a time, so peak memory follows the largest layer instead of the sum of all layers. The output is unchanged byte for byte.In both MVT and MLT, a tile is a sequence of independently encoded layers. Every per-layer step (clipping, snapping, drop masks, clustering, coalescing, Morton feature order) depends only on that layer. So a tile can be built by encoding each layer on its own and concatenating the encodings in layer order. The new
LayeredTilerdoes this:add_layer()runs the existing tile loop on one layer. The loop is unchanged; it is factored intogenerate_tiles_into(), whichgenerate_tiles()now calls. Each tile's raw layer encoding goes to a temporary spool file, with a smalltile_id -> [(offset, len)]index, and then the layer is dropped.finish()reads each tile's encodings back in layer order, concatenates and gzips them, and writes the archive through the existingTileSpool/write_pmtiles_from_spool(). Assembly holds at most 64 MiB of raw tile data at a time (one oversized tile still goes alone), so this step doesn't grow with the number of layers.freestile()use it for every multi-layer, non-categorical call. Single-layer calls and categorical clustering are unchanged. Generated feature IDs still continue across layers.freestile_layers(layers, output, ...)also loads layers lazily. It takes(name, source)pairs or a generator, where a source is a GeoDataFrame, aFreestileLayer, a GeoParquet path or a zero-argument callable. This is the path-based multi-layer input asked for in Multi-layered pmtiles file without loading all layers into memory? #17. In R, the layers are already in memory as sf objects, so the saving there is the Rust copy of the features and the per-layer tile maps. I did not add an R equivalent offreestile_layers(). Happy to add one if you'd like the APIs to match.gzip_level(from the stacked PR) applies to the layered path as well.Vec.git diff -wshows the small change.Memory and time. Synthetic data: an n x n grid of adjacent square cells (a dense polygon coverage) in WGS84, with
cell_idand one float column per layer, tiled at z10-15. Each run is a fresh process; peak working set is from psutil on Windows, 8 cores. The script is below. "Before" calls_freestile()with all layers parsed at once, which is whatfreestile()did with a dict of layers.Python, 90,000 cells per layer,
freestile_layers()with GeoParquet paths:R, 40,000 cells per layer, sf objects built in the session (they stay resident),
freestile()on a named list:Wall time was the same within run-to-run noise (about 10% on this machine). The rest of the peak growth from 1 to 10 layers is the tile index and the Python allocator.
Validation:
tests/layered.rs, added as a CI step. It uses five layers with different zoom ranges: two cell grids, a small grid at z12-13, lines and points. It checks byte identity withgenerate_pmtiles()for MVT and MLT under default snapping, no snapping, point clustering, coalescing, anddrop_rate+base_zoom+gzip_level = 6, with assembly budgets of 1 byte and 1 MiB. It also checks that a tileset with no tiles fails like the in-memory path and leaves no file, that an invalidgzip_levelis refused before any output, and that the spool appends correctly after reads. Byte identity with coalescing depends on the reproducible-coalesce fix this PR is stacked on.nctileset (polygons, boundary lines, centroids) with 10 configurations: MVT and MLT x default,simplification = FALSE,drop_rate+base_zoom, clustering, andgenerate_ids = FALSE. The archives are byte-identical betweenmainand this branch. Fulltestthatsuite: 0 failures (the skips are DuckDB/GeoParquet tests the CRAN build doesn't include).tests/test_layered.pychecks byte identity against the all-layers_freestile()call (MVT and MLT) and throughfreestile(), lazy sources (paths, callables, generators), and duplicate/empty refusals.test_gzip_level.pygains layered cases. Full suite: all pass. Wheel built with--no-default-features --features geoparquet, so the DuckDB tests skip.tests/layered.rswas run through a small harness crate that path-depends onfreestiler-core. On my Windows machine, the dev-dependencymlt-core->fastpforcan't download CPM.cmake (TLS error), socargo testin the crate doesn't build there. The CI step runs the test directly.rustfmt --checkis clean on the new code (I didn't touch existing unformatted code).Notes and limits:
finish(). On the 10-layer run above that was several hundred MB in the system temp directory, next to the existing tile spool.Reproduce the Python measurement:
(
peak_wsetis Windows-only; on Linux/macOS useresource.getrusage(resource.RUSAGE_SELF).ru_maxrss.)Closes #17.
I prepared this change with AI assistance (Claude Code) and reviewed it before submitting.