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

Cache container position for DomUtil.getMousePosition #2335

Closed
mourner opened this issue Dec 25, 2013 · 5 comments
Closed

Cache container position for DomUtil.getMousePosition #2335

mourner opened this issue Dec 25, 2013 · 5 comments
Milestone

Comments

@mourner
Copy link
Member

mourner commented Dec 25, 2013

Profiler says that most of the time during mouse interactions is spent on getting the current mouse position relative to map container, and specifically container position (container.getBoundingClientRect() and container.clientLeft/Top).

We could cache it under certain conditions to get rid of the slowdown, but this is somewhat tricky because we need to avoid out-of-sync situations. One way is to put a window.onscroll handler when we mouseover the container, reset cache on scroll and use cached otherwise. But this may have side effects so needs to be tested thoroughly.

@mourner
Copy link
Member Author

mourner commented Dec 25, 2013

cc @danzel

@mourner
Copy link
Member Author

mourner commented Dec 26, 2013

Weird thing about that is that getBoundingClientRect only takes a lot of time on heavy examples such as drawing lots of features with Canvas, but it's not related to DOM tree size since Canvas is one element... Mystery.

@danzel
Copy link
Member

danzel commented Dec 28, 2013

Could you share an example this is easy to reproduce on?
What you've suggested sounds like a good plan if the hit is meaningful :)

@danzel
Copy link
Member

danzel commented Dec 28, 2013

Are we manipulating the DOM, then calling those functions?
If we are then we might be causing a reflow

@mourner
Copy link
Member Author

mourner commented Dec 30, 2013

It's easy to reproduce with the debug/vector/geojson.html example — just start the profiler and mouseover like crazy over states. I've made the optimization above (cache-mouse-pos branch), but for some weird reason, while it shows a significant improvement in profiler, it seems not to affect real-world performance at all (e.g. FF lags on bug geojson as much as it was, while Chrome is as smooth with the patch and without). So closing for now.

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

2 participants