[Doc] TileLayer renderSubLayers usage for better performanceΒ #6810
Description
Link
https://deck.gl/docs/api-reference/geo-layers/tile-layer
Description
Original discussion: #6754:
But there is a more general issue in TileLayer. When diffProps returns a false positive, a normal layer will just perform an unnecessary redraw, which is not terrible. TileLayer on the other hand will invalidate all layer cache and rerender all sublayers, which can be expensive.
I believe the problem lies in the original design that TileLayer automatically forwards all of its props to renderSubLayers. It is therefore impossible to determine if an arbitrary prop change is meant to affect the tile layer itself (tile fetching and culling), or the generation of sub layers. Since renderSubLayers may return anything, we cannot pre-define the prop types of TileLayer to offer the same level of optimization as other official layers.
A "proper" fix that aligns the TileLayer behavior with other layers is to avoid exposing TileLayer to the sub layer props:
/// BAD
new TileLayer({
data: ...,
getTileData: ...,
maxZoom: 14,
parameters: {},
getLineWidth: f => ...,
getFillColor: f => ...,
getLineColor: lineColor,
getPointRadius: 4,
renderSubLayers: props => new GeoJsonLayer(props)
});
/// GOOD
new TileLayer({
data: ...,
getTileData: ...,
maxZoom: 14,
renderSubLayers: props => new GeoJsonLayer(props, {
parameters: {},
getLineWidth: f => ...,
getFillColor: f => ...,
getLineColor: lineColor,
getPointRadius: 4
}),
updateTriggers: {
renderSubLayers: [lineColor]
}
});
Both approach work with the current release, but the second is much more performant in React with managed view states.
We can update the documentation and examples to promote the latter, and deprecate the first use case in the next major release.