Skip to content

perf: Cull root tiles in raster-tileset to viewport - #464

Merged
kylebarron merged 2 commits into
mainfrom
kyle/perf-cull-root-tiles
Apr 24, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/perf-cull-root-tiles

Conversation

@kylebarron

@kylebarron kylebarron commented Apr 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Bound the z=0 root-tile allocation in getTileIndices so descriptors with very large root matrices (e.g. single-level zarr at native resolution) don't instantiate millions of RasterTileNodes before frustum culling has a chance to run.

  • New createRootTiles helper owns the branching. Small root matrices (≤ MAX_ROOT_TILES_NO_CULL = 100) bypass all projection work and iterate every tile — identical behavior to the pre-patch traversal, so any existing OGC pyramid (1 root tile at z=0), Sentinel-2, ECMWF (18), etc. are unaffected.
  • Large root matrices intersect the dataset extent with the viewport's WGS84 bounds, project that into the source CRS via transformBounds (densifying 21 points per edge so a non-linear projection like UTM can't escape the 4-corner hull), and consult the root level's existing crsBoundsToTileRange. If the viewport and dataset don't overlap, traversal returns an empty root list.

Before this change, a ZarrLayer pointed at a dataset like the AlphaEarth Foundations GeoZarr Mosaic (global, ~10 m resolution, 4009984 × 1859584 px @ 256² tiles → ~114M root tiles) instantiated all roots on first render and hung the page.

Test plan

  • New unit tests cover the three code paths: huge-matrix viewport cull, non-overlapping viewport (empty), small-matrix pass-through (verifies projectFrom4326 is not called).
  • pnpm --filter @developmentseed/deck.gl-raster test — 62/62 pass locally (3 new + 59 existing).
  • pnpm --filter @developmentseed/deck.gl-raster typecheck — clean.
  • CI green on this PR.
  • Manual: examples/dynamical-zarr-ecmwf + examples/zarr-sentinel2-tci still render (small-matrix path — should be unchanged).
  • Manual: a large single-level zarr (AEF mosaic) renders without hang (large-matrix path).

🤖 Generated with Claude Code

The traversal's z=0 loop instantiated every tile in the coarsest level's
matrix upfront, relying on frustum culling downstream to discard the ones
outside the viewport. For traditional OGC pyramids that's fine (z=0 is ~1
tile), but single-level Zarr descriptors can be thousands × thousands of
tiles at their native resolution — e.g. a 4009984 × 1859584 px global
raster at 256² tiles would instantiate ~114M RasterTileNodes at startup,
effectively hanging the page.

Cull to the intersection of the dataset extent and the viewport's WGS84
bounds: project the four corners into the source CRS via
descriptor.projectFrom4326 and consult the root level's existing
crsBoundsToTileRange. Typical viewport → tens of root tiles. If the
viewport and dataset don't overlap, traversal is skipped entirely.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron kylebarron changed the title perf: Cull root tiles to viewport before instantiation perf: Cull root tiles in raster-tileset to viewport Apr 24, 2026
Review feedback on #464:

- Introduce MAX_ROOT_TILES_NO_CULL = 100. Small root matrices (any typical
  OGC pyramid, ECMWF's 3×6=18, etc.) bypass the projection path entirely
  and behave bit-identically to the pre-patch traversal. Only descriptors
  with > 100 root tiles pay the projection cost.
- Move the culling into createRootTiles() so the call site stays a single
  helper invocation and the branching logic is self-contained and testable.
- Project the viewport-intersected bounds via transformBounds (21 samples
  per edge) instead of the 4-corner AABB, so non-affine projections like
  UTM cannot escape the hull.

Rename test file + fixtures to track the new entry point.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron
kylebarron merged commit 844349c into main Apr 24, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/perf-cull-root-tiles branch April 24, 2026 14:58
@ds-release-bot ds-release-bot Bot mentioned this pull request Apr 24, 2026
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.

1 participant