[] add a cache to style-layer-index so we don't recalculate keys #8122
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.
Launch Checklist
Test case: 33000 post codes are displayed on a map in a single fill layer. The tileset that its based upon contains postcodes for other countries so to reduce memory usage - a filter is applied on the layer so that only the 33000 postcodes that we're interested in are displayed.
Next we add a second layer for region outlines. When we mouseover a region - we set this "highlight" layer to show the single item.
Issue is that the speed of updating the "highlight" layer is slow. Profiling has shown this is due to the filter applied on the original region layer. When the "highlight" layer is changed - a broadcast event is sent to each tileworker - with the updated style. The tileworker then updates its styles based on the broadcast - and calculates a key for each layer. The key includes the filter - so to make the key it requires iterating over the 33000 items.
However this layer isn't one which is changing. In this case it seem a waste to have to regenerate the key.So add a key cache to the style_layer_index. When the key is calculated - save it in the cache. For updated layers - remove the key from the cache so we get a new key generated. For layers which stay the same - just use the existing key from the cache.
With this change - the testcase average time to display a hightlight was 381.03ms - whereas without the change the average highlight time is 830.58
@mapbox/studio
and/or@mapbox/maps-design
if this PR includes style spec changes@mapbox/gl-native
if this PR includes shader changes or needs a native port