Faster tile loading performance improvements - #21
Open
droidgren wants to merge 1 commit into
Open
Conversation
Three fixes in the tile-request path, from a pass over the app against MapLibre's large-data guide. Contour layers now set minzoom (contour-lines 10, contour-labels 11). contour-lines already faded to line-opacity 0 below native z11.5, but a layer painted at zero opacity still counts as using its source, so MapLibre kept asking maplibre-contour to build tiles that then rendered invisibly. Measured with a headless MapLibre harness: contour tile requests at z8/z9.5 go 6 and 4 -> 0, with z11 and z13 unchanged at 4 and 7. This saves worker and protocol work, not DEM downloads - Mapterhorn requests below z11 were already zero, since mlcontour skips the fetch when no threshold covers the zoom. Elevation tiles now serve cache-first with no revalidation. tiles.mapterhorn.com is a static dataset addressed by z/x/y, but shared the stale-while-revalidate branch with mutable basemap hosts, so every cache hit still fired a background fetch that could only return identical bytes. Three consumers request the same DEM URLs: MapLibre's raster-dem source, maplibre-contour's worker, and the canvas Image cache behind the analyses. Verified against the real service worker: 3 repeat DEM requests go 3 -> 0 network hits, while basemap revalidation stays at 3 -> 3. Cache eviction is amortized. putTileAndTrim called cache.keys() - enumerating the whole tile cache - after every put, so a fast pan storing 30 tiles re-walked the index 30 times. Trimming now runs once per 50 puts, guarded against overlap, and cuts back to a low-water mark so the cap and the floor form a hysteresis band. The put counter is seeded near the interval because a service worker is torn down after a short idle, which would otherwise reset the count every session and let the cache grow unbounded. With the per-put scan gone, TILE_CACHE_MAX rises 400 -> 1200; a viewport can pull three tile families at once. Verified bounded at 1200 after storing 1400 distinct tiles. Investigated and left alone: tileSize 512 on the DEM source is correct, the eager raster-dem source costs nothing (tiles load only when used || usedForTerrain), maxTileCacheSize is applied as Math.min(value, default) and can only shrink the cache, volatile does not exist in v6.2.0, and clustering does not apply to DOM markers.
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.
Enhance tile loading by preventing unnecessary tile requests for contour lines at low zoom levels, serving elevation tiles directly from the cache, and optimizing tile cache management to allow for more efficient storage and retrieval. This update significantly reduces network requests and improves responsiveness during panning.