Skip to content

perf: don't scan every tile coordinate when filtering z15+ tiles - #959

Open
dktue wants to merge 1 commit into
systemed:masterfrom
dktue:perf/lossy-foreach-set
Open

dktue wants to merge 1 commit into
systemed:masterfrom
dktue:perf/lossy-foreach-set

Conversation

@dktue

@dktue dktue commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Gain: tile filtering above z14 no longer scales with 4^zoom. Monaco at maxzoom 17: filtering z15/z16/z17 11.4 s / 43.0 s / 174.5 s → 0 ms; whole run 239.3 s → 0.47 s (−99.8%). Same tiles and features.

Tile filtering for zooms above 14 tested every possible tile coordinate: LossyTileCoordinatesSet (used for z15+) had no forEachSet override, so the generic loop called test() 4^zoom times, e.g. 2^34 at z17, whatever the size of the area.

On Monaco with maxzoom 17 that is 11 s for z15, 43 s for z16 and 175 s for z17, so 239 s of a 239 s run. For larger areas or z18 it grows to many minutes, independent of the actual number of tiles.

LossyTileCoordinatesSet::forEachSet now expands the tiles of the underlying (z14) set into their children. It keeps the documented x-major, y-minor order: one column of underlying tiles becomes scale columns.

Monaco, OpenMapTiles config with maxzoom/basezoom 17, --threads 1:

master patched
filtering z15 / z16 / z17 11.4 s / 43.0 s / 174.5 s 0 / 0 / 0 ms
total wall time 239.3 s 0.47 s
tiles written (all zooms) 340 340, identical list
features per layer and zoom identical

Adds a unit test comparing forEachSet on a wrapped set with a full scan, including the order; it also passes on the old code.

🤖 Generated with Claude Code

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