This question is for someone who understands the internals of MapBox GL JS.
I'm using MapBox GL JS to render a geographic map of up to 40,000 polygons, each of which is colored based on the "owner" of that polygon. There are typically many polygons per owner and the "owner" of each polygon may change over time. The number of owners can vary from one to around 1,000. I'm having performance problems (which vary depending on how I approach it), so I've tried a few different strategies.
- Using data-driven styling for "fill-color", where I have a single source and a single layer. I've tried both the polygon id and the "owner" id as the category for the data-driven styling.
- Using filtered layers, where I have a single source and a separate layer for each "owner". Again, I've tried both the polygon id and the "owner" id as the criteria for filtering.
- Using a separate source and layer for each "owner".
Option three has the best drawing speed. The layers are rendered very fast as I zoom and pan. But I have to call setData whenever I change the owner of a layer and setData leaks memory so I eventually end up with the page crashing. This issue, 2607, was closed as not actionable, so I don't expect a resolution to this.
Options one and two draw okay with the initial zoom, but when I zoom in they are very slow to re-draw the tiles. I am stuck looking at the jagged, low detail tiles until the rendering catches up after 20-30 seconds. Note that if I use the "owner" id instead of the "polygon" id, I still need to call setData when an "owner" changes which will lead to the memory leak. If I use polygon id, I just need to update the layer filters or fill-color categories when the "owner" changes. However, I don't get a noticeable performance difference if I use "polygon" id so I think that's okay.
So my question is why is option three so much faster to render when I zoom in? Does it have to do with the number of workers assigned to drawing? In options one and two, there is a single source so does that mean the drawing is only using a single worker? Whereas in option three, there is a separate source for each "owner" so I have multiple workers doing the drawing?