-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of addLayers by preallocating array #988
base: master
Are you sure you want to change the base?
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. |
Presently,
addLayers
pushes a new element ontoMarkerClusterGroup._needsClustering
for 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
addLayers
call time from 8.9s to 0.5s.