Leaflet.markercluster icon indicating copy to clipboard operation
Leaflet.markercluster copied to clipboard

Slowness detected with 50,000 Pins on Latest Chrome(74.0.3729)

Open kaleemullah opened this issue 5 years ago • 21 comments

  • [x] I'm reporting a bug, not asking for help
  • [ ] I'm sure this is a Leaflet.MarkerCluster code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
  • [x] I've searched through the issues to make sure it's not yet reported

How to reproduce

  • Browser (with version) I'm using: Chrome (Version 74.0.3729.131 (Official Build) (64-bit))
  • OS/Platform (with version) I'm using: macOS(10.14.4)

Just visit the official url, with 50,000 items, on aforementioned chrome version(which is latest): https://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.50000.html

What behaviour I'm expecting and which behaviour I'm seeing

Show map and load data in few seconds but it's taking around 2 mins to show map and then load pins. However on safari, it's loading in ~10 secs.

Minimal example reproducing the issue

  • [x] this example is as simple as possible
  • [x] this example does not rely on any third party code

kaleemullah avatar May 13 '19 10:05 kaleemullah

Same issue here. All of a sudden our maps with ~50.000 markers takes ages to load in Chrome 74.

Example: https://five.epicollect.net/project/campaign-education

Works fine in other browsers and previous versions of Chrome.

We tested (on a Mac)

  • Opera
  • Safari
  • Firefox
  • Chrome 73

Any suggestions? Can we help somehow? @danzel

mirko77 avatar May 20 '19 17:05 mirko77

I've been working on a workaround lately.

The idea is that instead of adding all markers in one step, I've splitted my markers in group of 2000 and add them one after the other using MarkerClusterGroup.addLayer.

Instead of spending for 20 second in clusters creations, it goes down to 660 ms for an input of 16000 markers.

tetedacier avatar May 21 '19 13:05 tetedacier

@tetedacier so you are adding multiple layers, one per each group? Is it not what addLayers and the chunked option does already? We used to add 50.000+ markers in a few seconds.

The thing is everything has always worked fine until Chrome 74, so I wonder what they changed in the browser to cause this 50x slowness compared to before

mirko77 avatar May 21 '19 13:05 mirko77

It seems that the addLayers function is having trouble with the new version of chrome. Try to iterate over your markers and add them one by one as @tetedacier said with addLayer. Fixed my issues with 70k markers.

mathiaslaramee avatar May 22 '19 05:05 mathiaslaramee

so yeah trick is to add markers one-by-one instead of a big chunk at once.

kaleemullah avatar May 22 '19 08:05 kaleemullah

I dont think this should be closed though - the issue still persists with addLayers which is supposed to handle this kind of functionality .. I guess?

mathiaslaramee avatar May 22 '19 08:05 mathiaslaramee

I would not close this either, addLayers() does not work as it should. There are some reasons that function was recommended I guess.

Is there any chance to fix that function instead of applying workaround??

If that is not possible, the docs and the 50K example needs to be updated.

mirko77 avatar May 22 '19 10:05 mirko77

@mirko77 @mathiaslaramee Agreed, I opened it already :)

kaleemullah avatar May 22 '19 10:05 kaleemullah

This sounds like a chrome bug. I recommend someone raises an issue with them, or see if there is an already existing one.

danzel avatar May 22 '19 20:05 danzel

This sounds like a chrome bug. I recommend someone raises an issue with them, or see if there is an already existing one.

I would do that but what do I report? We will have to look for the Javascript native functions in addLayers() that do not work as they should and build a fiddle for the Chrome guys.

mirko77 avatar May 23 '19 08:05 mirko77

Javascript changes in Chrome 74, do anything ring a bell? https://v8.dev/blog/v8-release-74

mirko77 avatar May 23 '19 08:05 mirko77

var cnt = 1
for (var i = 0; i < addressPoints.length; i++) {
			var a = addressPoints[i];
			var title = a[2];
			var marker = L.marker(L.latLng(a[0], a[1]), { title: title });
			marker.bindPopup(title);
			markerList.push(marker);
			cnt++
			if(cnt == 100){
			markers.addLayers(markerList);
		    map.addLayer(markers);
			markerList = [];
			cnt=1
			}
			
		}
		
		markers.addLayers(markerList);
		    map.addLayer(markers);
			markerList = [];

Using this approach i loaded 1 lac markers in 5 sec

image

rahulmahadik avatar May 29 '19 17:05 rahulmahadik

@rahulmahadik that is still using addLayers() ?

mirko77 avatar May 29 '19 17:05 mirko77

@rahulmahadik that is still using addLayers() ?

I posted the example code and screenshot

rahulmahadik avatar May 30 '19 03:05 rahulmahadik

@rahulmahadik that is still using addLayers() ?

I posted the example code and screenshot

The issue is on: Chrome (Version 74.0.3729.131 (Official Build) (64-bit)) macOS(10.14.4)

Are you using the above Chrome version/Mac version? If not, your example is not relevant. There are not any issues on other Chrome versions.

mirko77 avatar May 30 '19 09:05 mirko77

@rahulmahadik that is still using addLayers() ?

I posted the example code and screenshot

The issue is on: Chrome (Version 74.0.3729.131 (Official Build) (64-bit)) macOS(10.14.4)

Are you using the above Chrome version/Mac version? If not, your example is not relevant. There are not any issues on other Chrome versions.

I'm using Chrome Version 74.0.3729.169 (Official Build) (64-bit)

rahulmahadik avatar Jun 02 '19 06:06 rahulmahadik

I digged this issue deeper, since my split strategy stopped to be effective at 100.000 markers.

It seems that all the time is spent inside the hasLayers method.

I'm preparing a PR with a modified version of addLayers which doesn't call the hasLayer method since when I'm initially loading the markers, this method just consume time and allways return false.

tetedacier avatar Jun 03 '19 09:06 tetedacier

I digged this issue deeper, since my split strategy stopped to be effective at 100.000 markers.

It seems that all the time is spent inside the hasLayers method.

I'm preparing a PR with a modified version of addLayers which doesn't call the hasLayer method since when I'm initially loading the markers, this method just consume time and allways return false.

@tetedacier is hasLayers() called in the addLayer() methos as well?

mirko77 avatar Jun 03 '19 09:06 mirko77

@mirko77, Yes it is the same.

tetedacier avatar Jun 03 '19 10:06 tetedacier

My clustering code was slow too... But when I change the process order, the problem goes away:

  • Create cluster
  • Add the EMPTY cluster to the map
  • Add markers to the cluster

In this way, there is no lagging. So, add markers to the cluster AFTER the cluster has been added to the map. Maybe it helps.

petrot avatar Jun 05 '19 08:06 petrot

What @petrot writes seems to work successfully for me as well. Adding the MarkerClusterGroup to the map first and then adding my 70k CircleMarkers with addLayers seems to work just as before.

mathiaslaramee avatar Jun 06 '19 10:06 mathiaslaramee