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

Interaction calls getBoundingClientRect on mousemove events #854

Closed
tmcw opened this issue Dec 1, 2014 · 3 comments
Closed

Interaction calls getBoundingClientRect on mousemove events #854

tmcw opened this issue Dec 1, 2014 · 3 comments
Assignees

Comments

@tmcw
Copy link
Contributor

tmcw commented Dec 1, 2014

getBoundingClientRect triggers reflows because it requires style recalculation. It's best not to call this function on fast-firing event handlers.

@mourner
Copy link
Member

mourner commented Dec 1, 2014

Here's a way to approach this: Leaflet/Leaflet@5f85e12 — cache the value on map mouseenter (and assume the position of the map doesn't change while you're interacting with the map), then use the cached value.

Not sure why it didn't make much difference in my case though: Leaflet/Leaflet#2335 (comment) — needs reevaluation. Maybe I didn't see difference because I tested on barebones pages without a lot of elements.

@bhousel
Copy link
Contributor

bhousel commented Oct 7, 2015

@mourner Can you review 4e19ca2 when you get a chance?

@bhousel
Copy link
Contributor

bhousel commented Nov 20, 2015

Just putting a quick update here: I did try caching the offsets on mouseenter of the canvas container, but it caused some issues when there were multiple maps on the same page and they were both trying to reset the cache.

More info here: #1598 (comment)

@jfirebaugh and I chatted and we both agree that any minor performance bump this trick might get us is not worth the complexity of introducing a cache, and we can't think of a way to avoid calling getBoundingClientRect.

e.g. offset adjustment in the middle of a mousemove:
cached offset issue

Closing this issue as "wontfix" for now..

@bhousel bhousel closed this as completed Nov 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants