Select to view content in your preferred language

Performance issues and memory leaks opening popups and using FeatureLayers

1348
1
07-06-2018 10:01 AM
AndrewGallant
New Contributor

I have a map with a MapImageLayer with multiple sublayers and the capability to draw a polygon to select the set of all features contained within the polygon. After selection, I open a popup with the set of all features:

// Merge all the features into a single array of Graphics
const features = featureSets
  .map(featureSet => featureSet.features)
  .reduce((prevValue, curValue) => [...prevValue, ...curValue]);

if (features.length > 0) {
  const location = <__esri.Point>features[0].geometry;

  // Display the popup
  this.mapView.popup.open({
    features,
    location,
  });
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

With small selections (10's of features), there are no noticeable issues: the user selects features, and with an acceptably short latency, the popup opens on the first feature in the set. As the selection set becomes larger, however, the latency grows exponentially larger, the CPU usage hits 100%, the app freezes, and memory usage skyrockets. When the map finishes whatever it is doing, the app resumes, but whatever caused the memory spike is creating persistent object references that don't go away even after the map is destroyed, as the garbage collector never frees up that memory. If the selection is large enough (1000's of features), the browser tab will crash before it finishes doing whatever the heck it is trying to do.

Commenting out the call to open the popup eliminates the performance and memory spikes.

I don't know where to begin debugging this. I built a test app that is just a basic map, where a large set of features is loaded into a popup on the click of a button, and I get a different issue where calling MapView.popup.open never completes, but also somehow does not eat up CPU cycles.

I can get a similar performance issue by loading one of the MapImageLayer sublayers as a FeatureLayer and adding it to the map. If I load the layer as a FeatureLayer, CPU usage spikes to 100% for a few seconds with a small number of features, up to several minutes with 1000's of features. A map with 7000 features took 2 minutes to become usable, and if the user pans or zooms the map, CPU usage spikes again and the map freezes for 10-30 seconds before it becomes usable. I don't strictly need to load the layer as a FeatureLayer, but it would be desirable to be able to do so due to the flexibility of FeatureLayers vs MapImageLayers.

I've tried to replicate these issues with public data sets from the Sample Code pages, and I cannot. It seems like there is something either specific to my ArcGIS server or specific to my data that is causing these problems. Unfortunately, the data is private, so I cannot share it.

Does anyone have any ideas about why these problems might be happening, how I can debug them, or any workarounds that might alleviate them?

0 Kudos
1 Reply
by Anonymous User
Not applicable

basically, this is why I use dynamic layers. webGL has requirements that make it not a universal solution and also has memory leak issues and security implication. I think the long term solution for the serious performance issues with Esri viewers is to have a two-fold way of displaying any and all layers, as a default... Vector tiles for display. When a user clicks it gets the popup from a feature layer. They are paired. This should happen under the hood and the JS API and we should not have to do any extravagant programming. Should work almost transparently under the hood.  Because the way it is now... there are just performance issues with displaying a lot of data if you want to also query it for popups.  Vector tiles are blazingly fast. But they 'don't support real popups' so to speak... yet. I think this would be the easiest way to implement it using existing tech.  Or they could simply make vector tiles also support attributes but that is probably less realistic. One way or another though the platform needs to get a handle on viewer performance.

0 Kudos