-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Highlight polygons becomes extremely slow when large number of features present #2225
Comments
My personal experience is that when you only want to deal with a proportionally small set of features out of a set of many features, such in your use case, it's much more efficient to maintain a separate GeoJSON source that you transfer your "filtered" features to. In your example the filtering has to be carried out over the entire data set without any efficient indexing every time you hover over a new feature. If you instead copy the feature geometry of the feature you hover over to a separate source, the only lookup carried out frequently will be the featuresAt, which is an indexed lookup. I've used this approach successfully for sets with hundreds of thousands of features, and a variant of it (including source) can be found at the Mapbox Blog: https://www.mapbox.com/blog/properties-philly/ So, in your case, if you want to try it out, add a new GeoJSON source to your map, such as |
@rantao why do you do |
Based on...
... I believe this was an effort to try to limit when the featuresAt-call is carried out. But I agree, this will only hamper performance even more. |
@averas avoid |
@mourner Yep. Again, this was probably a trail-and-error measure by @rantao to try to increase performance without any deeper analysis of the behind-the-scenes workings. I have several implementations of both featuresIn and featuresAt on very large datasets (millions of features), and as you say, as long as you keep the query as narrow as possible (for example with the smallest bbox possible) things are quite performant even with these data set sizes. That's why I have a hunch this is rather related to the filtering which I believe (correct me if I'm wrong) is not indexed at all, so if you change a filter on a 10k GeoJSON data source you're looking at a full scan of that set, i.e. O(N), |
@averas yes, One good strategy of improving hover performance on the app side is throttling the mousemove handler. Try 16ms (60fps), then 32ms (30fps) etc. until performance is acceptable. |
Another part that's quite expensive is |
@averas is correct. I was only using the As for a live demo, unfortunately my data is on my local, so it's not easy to create a jsfiddle. I am currently trying some of the suggestions from both @mourner and @averas (that philly example is pretty cool). Will update whether anything solves this issue :) Thanks so much! |
So removing In the end, there should be an update to how |
Your stream of events should be pushed through a I believe your suggestions on Did you try my other suggestion? Copying the features to a separate source/layer. |
The problem is we don't know when GPU finishes rendering, this operation is async and has no callbacks. The best we can do is throttle calls like |
mapbox-gl-js version: v0.15.0
Steps to Trigger Behavior
Expected Behavior
The hover highlight should be immediate with movement of the mouse, even if you move the mouse fast.
Actual Behavior
There is an increasing lag as the # of features in the canvas increases and as you increase the speed of mouse movement. You can see a trail of polygons being painted if you move your mouse across the screen before it finally 'catches up.' It looks like the hover requests are queued up instead and not rendered async.
Video of the delayed highlight with ~5000 features
I understand this was improved A LOT already in a recent update (#2174). But it is still not usable for my scenario when there can be > >10,000 features easily. And there is already a visible performance issue at even > 1,000 features. I've tried to only show hover when there are less features on the canvas but it makes for a confusing/broken ux so i will turn it off until it can be more performant.
Code for adding highlight layer:
Code for triggering highlight of polygon on mousemove:
The text was updated successfully, but these errors were encountered: