Skip to content

fix(deck.gl-raster): unload a tile whose load finishes after it was unloaded - #878

Merged
kylebarron merged 1 commit into
mainfrom
kyle/tile-unload-leak
Nov 16, 2026
Merged

kylebarron merged 1 commit into
mainfrom
kyle/tile-unload-leak

Conversation

@kylebarron

@kylebarron kylebarron commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron.

Closes #876

Problem

A tile that is unloaded while it is still loading can leak its textures:

  1. deck.gl 9.4.1 evicts tiles that are still loading when its cache is over the limit, and calls onTileUnload while their content is still null. RasterTileset2D's own wrapper does the same when it aborts an unwanted load.
  2. If the load still returns data, because getTileData doesn't stop at the abort or was never aborted, deck.gl keeps the result as the tile's content.
  3. The tile has already left the cache, so onTileUnload never runs for it again, and whatever getTileData created is never freed.

#876 describes this for a COGLayer tile aborted mid-decode. It also happens with no abort at all: ZarrLayer doesn't abort unwanted loads, and aef-mosaic sets maxCacheSize: 10 with about 15 tiles in view, so short pans evict tiles mid-load.

Fix

RasterTileset2D remembers the tiles it has passed to onTileUnload, in a WeakSet. When one of them finishes loading, it calls onTileUnload again, now with content, instead of onTileLoad. This is the "unload late results centrally" option from #876, so custom getTileData pipelines are covered too.

#728 knowingly left this case to the upstream fix. This brings a guard back for the interval before that fix is published. visgl/deck.gl#10883 makes the same change in deck.gl's own load handler, due in 9.4.2. There, deck.gl unloads the late tile and returns before it calls onTileLoad, so this guard is never reached and nothing is unloaded twice. The guard can go when the overrides in #863 go.

Measured

aef-mosaic on main with deck.gl 9.4.1, headless Chromium at 1280 x 800: 16 round trips of a 300 px pan, then a wait until no loads were left. An orphaned texture is a tile texture that no live tile holds and that was never destroyed.

Build Orphaned tile textures Texture Memory Textures Active
main, run 1 11 122 MB 47
main, run 2 8 109 MB 44
This PR 0 76 MB 36

With this PR, 15 tiles finished loading after they had been unloaded empty, and all 15 were freed.

Not covered

Test plan

  • A new unit test evicts tiles that are still loading, then lets their data arrive. It fails on main, where the tiles are never unloaded, and passes here. It runs with abortUnwantedLoads both off and on.
  • The package's 262 tests pass, and typecheck and biome ci pass.
  • The pan measurement above, run with and without the change.
  • Not checked in a browser: the COGLayer mid-decode case from A tile aborted while it decodes still gets a texture, which is never freed #876. The unit test with abortUnwantedLoads on follows the same path.

🤖 Written by Claude Code

…nloaded

deck.gl 9.4.1 evicts tiles that are still loading and calls onTileUnload
before they have content. When such a load still returns data, deck.gl
keeps it as the tile's content, but the tile has left the cache, so
nothing unloads it and its textures leak.

RasterTileset2D now remembers the tiles it has unloaded. When one of
them finishes loading, it is unloaded again, now with its content,
instead of being reported loaded. visgl/deck.gl#10883 does the same in
deck.gl 9.4.2, where this guard is never reached.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅

@kylebarron
kylebarron merged commit 89ad109 into main Nov 16, 2026
5 checks passed
@kylebarron
kylebarron deleted the kyle/tile-unload-leak branch November 16, 2026 23:13
kylebarron added a commit that referenced this pull request Nov 16, 2026
Resolves the conflict in RasterTileset2D.setOptions with #878 by keeping
both changes: the onTileLoad wrapper and the best-available replacement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Nov 24, 2026
…s redundant (#886)

> [!NOTE]
> This PR was written by Claude (Claude Code) on behalf of @kylebarron,
not by @kylebarron.

Closes #863

### Problem

deck.gl [9.4.2](https://github.com/visgl/deck.gl/releases/tag/v9.4.2)
includes visgl/deck.gl#10883:
- `Tileset2D.finalize` calls `onTileUnload` for every cached tile.
- A tile whose load finishes after it left the cache is unloaded instead
of reported loaded.

Our workarounds for 9.4.1 do the same thing. On 9.4.2, they unloaded
every tile twice. That destroyed default-pipeline textures twice and ran
user `onTileUnload` / `onSourceUnload` callbacks twice (#863). With the
lockfile moved to 9.4.2, five tests failed this way before this change.

### Change

This is option 2 from #863:
- Every `@deck.gl/*` spec, including peer deps, pnpm overrides and
examples, now requires `^9.4.2`. The lockfile moves only deck.gl.
- `RasterTileset2D`: removes the `finalize` override and the late-load
guard from #878. The `abortUnwantedLoads` wrapper of `onTileUnload`
stays.
- `MosaicTileset2D`: removes the `finalize` override. `reloadAll` stays,
because deck.gl's `reloadAll` still drops items without unloading them.
It now calls deck.gl's `finalize`.
- `custom-projection` example: removes its `finalize` override.
- `MosaicLayer.onSourceUnload` docs: an item that is still opening is
unloaded with no source, then again with its source once the open
finishes.
- `onnx-embeddings/NOTES.md`: no longer says the mid-load eviction leak
applies.

### Test plan

- [x] `deck.gl-raster` (263), `deck.gl-geotiff` (224) and `deck.gl-zarr`
(81) tests pass on 9.4.2.
- [x] One test encoded 9.4.1 behavior, with no unload at `finalize` for
a loading tile. It now expects an unload right away with no content,
then another once the data arrives.
- [x] `biome ci` passes.
- [ ] Not checked in a browser.

Follow-up: switch the examples to `@deck.gl/maplibre` (#661), which
visgl/deck.gl#10734 in 9.4.2 unblocks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_011cLtCQHxJfGKqmXPYrjSPA

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A tile aborted while it decodes still gets a texture, which is never freed

1 participant