mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.21k stars 2.22k forks source link

Allow limiting number of concurrent vector tile requests #13211

Open jobblefrobble opened 4 months ago

jobblefrobble commented 4 months ago

Motivation

If you have many vector tile sources present on the map then animations can send out a huge number of concurrent requests, potentially overwhelming the browser and throwing ERR_INSUFFICIENT_RESOURCES errors which don't get retried by mapbox resulting in missing tiles. More seriously it can disrupt all other concurrent requests being sent out by the browser.

I think this is also related to some of the problems outlined by #13208

Design Alternatives

There was talk of a TileQueue on #6643 :

I've looked into how OpenLayers handles raster tile loading, and I believe the reason why their equivalent is fast is that they use a TileQueue data structure that makes sure there are never more than 16 tiles loading in parallel or requested at once in one frame. This makes it avoid requesting short-lived tiles that e.g. get requested on zoom in near the borders of the map and then immediately go off the view when zooming further during an animation. This might be a possible solution to this feature request https://github.com/mapbox/mapbox-gl-js/issues/5482, and we should definitely explore a similar approach.

I'm wondering if such a thing could be added for vector sources too? Though maybe 16 is too conservative a number for vector tiles

Mock-Up

It would be nice to expose a variable similar to the existing mapboxgl.maxParallelImageRequests, but applying to vector tiles rather than images. e.g. mapboxgl.maxParallelVectorTileRequests

jobblefrobble commented 4 months ago

I've started work on this in a fork, will aim to put out a PR sometime soon, though will likely need guidance around using config values within workers and how best to test it πŸ™‚

jobblefrobble commented 3 months ago

I've submitted a draft PR for this with some questions about injecting config values into workers πŸ™‚

https://github.com/mapbox/mapbox-gl-js/pull/13247