Re:Vanilla JS, fast, lightweight, cross-platform framework
by pooriaazimi on Sunday August 26, 2012 @05:22PM
(#4436257)
Question: is the 'Speed Comparison' for real? I find it really, really hard to believe. Surely jQuery & co. revert to native implementations (if they exists, as they do in all modern browsers) for things like `document.getElementById` and don't iterate over the whole DOM.
[ Parent
| on HN ]
Re:Vanilla JS, fast, lightweight, cross-platform framework
by masklinn on Sunday August 26, 2012 @06:15PM
(#4436438)
> is the 'Speed Comparison' for real?
Depends what you mean by "for real". The document.getElementsByTagName comparison is bullshit: gEBTN is lazy, just calling it basically doesn't do any work, it just allocates a NodeList object and returns.
If you serialize the nodelist to an array or use document.querySelector instead (it returns an array) you get ~3x between the native version and the slowest libraries, not 400x.
Re:Vanilla JS, fast, lightweight, cross-platform framework
by Timmy_C on Sunday August 26, 2012 @05:58PM
(#4436387)
Yeah, Sizzle will grab an element using `document.getElementById()` but only after checking the nodeType of the context, ensuring the selector is a string and running the selector through a regular expression.
Re:Vanilla JS, fast, lightweight, cross-platform framework
by jfaucett on Sunday August 26, 2012 @06:04PM
(#4436399)
I just looked at the latest jquery and its each statement does not do a native fallback, which really surprised me. Also you have to keep in mind that a simple $('a.active').each(someFunc), has to run through the a lot of jq luggage, plus the initial http fetch of the library (which has come under criticism for its size).