title: How to deal with Large number of ClusterItems in Cluster - Android GoogleMaps V2
body: <p>I am using GoogleMapsV2. I have around 10 000 cluster items which I bulk add to ClusterManager (ClusterManager.addItems(Collection).</p>
  
  <p>My problem is that the clustering and de-clusterin process is lagging and slow. I believe it shouldn't be that slow with around 10 000 items. Testing on OnePlus3 (with 6GB or ram) so it's not the phone.</p>
  
  <p>Here is cluster relate code in activity:</p>
  
  <pre><code>// Rent markers
  rentMarkerList = new ArrayList&lt;&gt;();
  rentClusterManager = new ClusterManager&lt;OffersMarker&gt;(this, gmap);
  rentClusterRenderer = new OffersClusterRenderer(this, gmap, rentClusterManager);
      rentClusterManager.setRenderer(rentClusterRenderer);
  
  for (AdMarker adMarker : adsArray) { //&lt;-- adsArray.size() = 6500
      OffersMarker offsetItem = makeOffersMarker(adLocation, nrOfAds, realEstateAdIds, OffersMarker.DEALTYPE.SALE_CODE);
      rentMarkerList.add(offsetItem);
  }
  
  // Do bulk add of Markers into ClusterManager.
  rentClusterManager.addItems(saleMarkerList);
  rentClusterManager.cluster();
  </code></pre>
  
  <p>I went over my ClusterRenderer and I am not performing any large operations in onBeforeClusterItemRendered() and onBeforeClusterRendered().
  It seems that the application is much slower when doing Clustering than it is in de-clustering but that may also be because clustering is done usually on a much smaller zoom level and thus more markers are displayed.</p>
  
  <p>My android monitor shows that the clustering process alters the memory and CPU and not the GPU so it's not a graphics problem.</p>
  
  <p>Solutions I tried:
  Doing dynamic cluster rendering like described <a href="https://discgolfsoftware.wordpress.com/2012/12/06/hiding-and-showing-on-screen-markers-with-google-maps-android-api-v2/" rel="nofollow noreferrer">here</a>. In this case you loop through your markers list and see which are in the Viewport bounds so you only display those markers. This made the whole thing worse because I had to loop through all the 10 000 markers every time onCameraIdle... was called.</p>
  
  <p>Any ideas where to start optimizing this problem?</p>