Skip to content
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

Throttle mousemove internally #2337

Closed
wants to merge 1 commit into from
Closed

Throttle mousemove internally #2337

wants to merge 1 commit into from

Conversation

mourner
Copy link
Member

@mourner mourner commented Mar 25, 2016

Ref #2334. I’ve lost count of times where I gave advice to throttle mousemove whenever someone had performance issues with interactivity. I think mousemove should be throttled internally by default — it always helps with performance, and I can’t think of any drawbacks/gotchas in this particular throttling case.

This, coupled with the preventDefault fix in the example, makes the point dragging example much smoother. After we fix setPaintProperty triggering cascade, it’ll become butter-smooth.

cc @lucaswoj @jfirebaugh @ansis @tristen

@ansis
Copy link
Contributor

ansis commented Mar 25, 2016

Are there any cases where a user would want unthrottled events?

Does this solve the problems or just make them less severe? Could the work triggered by the events still cause backups?

Would it be better to throttle the actual work instead of the events that trigger the work? (should setData queue up new data if work is still in progress?)

If we throttle, we should throttle with requestAnimationFrame instead of setTimeout 16ms.

@mourner
Copy link
Member Author

mourner commented Mar 25, 2016

Are there any cases where a user would want unthrottled events?

I can't think of any, but let's see if anyone can.

Does this solve the problems or just make them less severe? Could the work triggered by the events still cause backups?

It's a part of the solution, which is "avoiding unnecessary work". It can't solve all the problems but it always improves performance in case expensive mousemove handlers.

Would it be better to throttle the actual work instead of the events that trigger the work? (should setData queue up new data if work is still in progress?)

I don't think so, because throttling the actual work can have unexpected side effects and introduce subtle bugs. But specifically in case of mouse events, I can't think of a case where it would cause problems.

If we throttle, we should throttle with requestAnimationFrame instead of setTimeout 16ms.

Agreed. Should we modify util.throttle to automatically use reqAnimFrame when time is 16ms or less, or should we do a separate util method in util/browser/browser.js?

@lucaswoj
Copy link
Contributor

This looks great!

👍 to a separate frameThrottle util method in util/browser/browser.js.

@mcwhittemore
Copy link
Contributor

Won't this break stopPropagation?

@jfirebaugh
Copy link
Contributor

Yes, and preventDefault.

I'm 👎 here. We've seen several instances where internal throttling in Leaflet caused issues and had to remove it. It just generally seems to be a bad idea to do it at the library level.

@mourner
Copy link
Member Author

mourner commented Mar 28, 2016

But you're strongly against exposing util methods like throttle in public too. And we can't use third-party utility libraries in our examples. What should we do here then? I'd really like to make our examples fast.

@mourner mourner closed this Mar 28, 2016
@bhousel bhousel mentioned this pull request Mar 28, 2016
@mourner mourner deleted the throttle-mousemove branch March 29, 2016 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants