Skip to content

refactor(examples): drop the source caches MosaicLayer no longer needs - #842

Merged
kylebarron merged 2 commits into
mainfrom
kyle/examples-drop-source-caches
Nov 5, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/examples-drop-source-caches

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

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

naip-mosaic and vrt-mosaic turned MosaicLayer's cache off (maxCacheSize: 0) and kept their own cache of opened sources. Until #839, each item in MosaicLayer's cache kept its whole COGLayer and that layer's textures, so caching items there was expensive. Now an item out of view keeps only its opened source. So both examples pass COGSource.open straight to getSource, and rely on MosaicLayer's cache.

Changes

  • naip-mosaic and vrt-mosaic remove their module-level source caches and maxCacheSize: 0. naip-mosaic still passes its epsgResolver to COGSource.open.
  • Spec: decision 16 says that the examples rely on MosaicLayer's cache.

One difference: the examples' caches kept every source they had ever opened, forever. By default, MosaicLayer's cache holds up to five times the items in view. So after a long trip, an item may have left the cache and must be opened again, though its header bytes are usually still in the range reader's cache.

Checks

In Chrome, panning through several areas and back:

naip-mosaic, zoom 11 vrt-mosaic, zoom 8
COGLayers alive 36, the items in view 15, the items in view
Texture memory 17 MB throughout 24-26 MB throughout
Back to the first area right after leaving it 285 ms, 0 requests 221 ms, 0 requests
Back after six areas 1.2 s, 8 requests, for sources opened again not tested

Neither example logged errors. The workspace typecheck, Biome, and both examples' vite build pass.

Ref #803

🤖 Written by Claude Code

naip-mosaic and vrt-mosaic turned MosaicLayer's cache off and kept their
own cache of opened sources, because each cached item used to keep its
whole COGLayer. Since #839, an item out of view keeps only its opened
source in MosaicLayer's cache, so both pass COGSource.open to getSource.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread examples/naip-mosaic/src/App.tsx Outdated
Comment on lines +387 to +390
// MosaicLayer keeps each opened source in its cache, so an item that
// comes back into view isn't opened again
getSource: (item, options) =>
COGSource.open(item.assets.image.href, { ...options, epsgResolver }),

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.

Just to clarify; how big is the MosaicLayer source cache? Is this set by maxCacheSize?

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.

Note

This reply was written by Claude (Claude Code), not by @kylebarron.

Yes. MosaicLayer passes maxCacheSize to its inner TileLayer, whose tile cache has one entry per item. Since #839, each entry keeps only the item's opened source.

  • Default: with maxCacheSize unset, deck.gl caps the cache at five times the items in view, recomputed as the view changes. In my checks, that was 180 sources for naip-mosaic at zoom 11, with 36 items in view.
  • Eviction: deck.gl trims the cache only when a new item is added, and it drops items out of view, oldest-opened first. It doesn't move an item to the back of the cache when it's used again, so this is first-in, first-out rather than least recently used. Each dropped item gets onSourceUnload.
  • maxCacheByteSize doesn't bound it yet (MosaicLayer's maxCacheByteSize leaves its cache unbounded #803).

The comment said that a returning item "isn't opened again", which only holds while the item is still cached. 4b3ee88 says how many sources the cache keeps.

🤖 Written by Claude Code

@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 0e01870 into main Nov 5, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/examples-drop-source-caches branch November 5, 2026 15:12
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.

1 participant