Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

> 6 lines of jQuery becomes 24 lines of JavaScript, but the speed goes from unacceptable to acceptable

Have you tried JQuery 1.2.6 yet? I've also had to drop down to raw DOM for performance, but I've found that many features that were unacceptably slow with 1.2.3 (mousemove events, $.map) have gotten quite usable. Events no longer copy the whole event object, map is linear time instead of quadratic, and I've heard $.extend got a major speed boost which'll speed up construction of all jQuery objects.



Map was quadratic before?! It seems like it would take deliberate effort to make it anything other than linear.


$.map has an interesting quirk in its spec: it flattens returned arrays into the result. This was implemented by calling concat() with each result, but concat creates a new array for its return value. So each iteration was creating a new array and copying over the previous values, which makes for a quadratic runtime in most JS runtimes.

(Curiously, in the benchmarks folks did in the Reddit thread, it looked like Firefox was not quadratic - which implies that Firefox either has some clever optimizations going on or does crazy things with concat().)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: