Improve performance of addLayers by preallocating array#988
Improve performance of addLayers by preallocating array#988pmarrapese wants to merge 6 commits intoLeaflet:masterfrom
Conversation
Cherry picked from Leaflet#988
Cherry picked from Leaflet#988
|
thanks for maintaining this project! Is there any chance someone could take a look at this? |
|
Made a minor but important update to this: |
|
I was half-way into building a cusom static clustered grid to solve this. 6.5s --> 1.2s with this solution @pmarrapese this is fantastic, please pull this :) |
|
Hi @pmarrapese , this seems like an important perf improvement and def would like to merge it. any minimal examples that could reproduce the efficiency improvements on jsfiddle? |
In the event leaflet sends "infinity" as a max or min zoom while generating the initial clusters, the loop to set up the grid clusters will crash the browser.
|
@ykzeng - Sorry for the wait here! Finally had some time to do a demo. Open the console for logging. My changes; using
|
|
@IvanSanchez @ykzeng please either start reviewing the PRs (this one is 4 years old!) or add more maintainers to the project with merge rights. |
Improve performance of addLayers by preallocating array
Presently,
addLayerspushes a new element ontoMarkerClusterGroup._needsClusteringfor each qualifying element inlayersArray. This is inefficient because the array is being resized upon every iteration, which is a very expensive operation. This problem really starts to become evident when adding a large number of markers.This pull request resolves this problem by preallocating the array instead of repeatedly resizing it. Using a dataset of 120,866 markers, this simple fix reduced my average
addLayerscall time from 8.9s to 0.5s.