-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Evaluate (when available) use of DOM Element#closest method #1868
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
Comments
We could only use it for cases where the selector has no jQuery selector extensions. I suppose we could try to validate it by calling Given how crappy the performance usually is on newer DOM/ES5+ methods it would be worth benchmarking to see if it's worth the effort. |
Unless jquery/sizzle#293 is accepted. :) |
Yep, i suspect there should be some pitfalls like that, i would like to see something like this as resolution of this issue. |
elem.closest() is in Chrome 40, which has been in Canary & Dev for a while. it'll be coming to beta in a wink. |
Yep, that's why I created this issue now |
We're WAAAY ahead of you, nyah-nyah! 😜 |
:p On Tue Nov 18 2014 at 8:58:43 PM Dave Methvin notifications@github.com
|
True, but it's currently not slow. Chrome is doing 30k ops/sec with today's code and Firefox is 50k. Considering all that we do there I'm surprised it's only about 5x faster! Plus we can't avoid having the current code path, we'll have to add another path being sure to call the old path for cases where |
Right, that is way i said we need comprehensive research (including implementation details) and not just one perf link. |
Haha, guys!! I'm merely just cross linking relevant stuff. Its also No rush from me. I'm so chill. |
Now that we've removed the pos exception from |
Oh yeah, awesome! Good call on removing positional selectors @gibson042! |
Any news here guys? The performance difference is noticeable. |
Do you have your test case? (Not a jsperf, but real code.) It's hard for me to imagine situations where this would save seconds, but the code could clarify it. |
The different isn't too big in simple examples - something like 30-50ms for 2000 calls. The actual code is very complex and has no public access anyway. Uncomment line 5 to see the timing when using jQuery's closest. |
@oriadam In websites with deep tree native closest much times faster than jQuery. Just try in dev console: // 50
e=document.querySelector('#\\3a 3b > div > div > div'); start=performance.now(); for(i=0;i<100000;i++) e.closest('body'); console.log(performance.now()-start); // 2800
e=jQuery(document.querySelector('#\\3a 3b > div > div > div')); start=performance.now(); for(i=0;i<100000;i++) e.closest('body'); console.log(performance.now()-start); |
If you need to find the closest ancestor of 100,000 nodes in a short period of time I would definitely recommend using the native method directly. It would be a good optimization for a case like that, but I wouldn't do it until the profiler shows that |
My real problem is IE which works significantly slower than Chrome and doesn't support any native optimization :) |
Specification - https://dom.spec.whatwg.org/#dom-element-closest
Its signature is pretty close to ours, it might beneficial to use it
The text was updated successfully, but these errors were encountered: