Skip to content

Faster tile loading performance improvements - #21

Open
droidgren wants to merge 1 commit into
mainfrom
perf/tile-loading
Open

Faster tile loading performance improvements#21
droidgren wants to merge 1 commit into
mainfrom
perf/tile-loading

Conversation

@droidgren

Copy link
Copy Markdown
Owner

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.

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.
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