Hacker News new | past | comments | ask | show | jobs | submit login

Pretty much any environment where you care about performance of your code, actually. A lot of the simple-looking jquery stuff is implemented with tons of indirection, branching, etc.

Just compare the work a browser has to do for something like:

  document.getElementById("foo").setAttribute("bar", "baz");
to the work needed for the jquery equivalent...

Now the good thing is that most consumers of jquery don't care about performance of their code (in that they're doing small enough amounts of stuff it doesn't matter much).




  > Now the good thing is that most consumers of jquery don't
  > care about performance of their code
Many do, but more do care about cross-browser compatibility and when you need to support IE6,7 home-rolled code is not likely to cut all the research and effort that's embedded in jQuery.


Out of curiousity I tested that particular statement, and you're right. Compared to

    $('#foo').attr('bar', 'baz');
your code is

30 times faster in Chrome 9

81 times faster in Firefox 3.6


47 times faster in Firefox 3.6.1 7 times faster in IE 8


In most cases, though, using jquery to do something like adding a class, or setting a value, is still plenty fast enough. We're talking about code that runs in the browser, where things move on human timescales. Don't optimize prematurely.


The problems start when you add a class to 10,000 elements on the page. And yes, I've seen pages doing this with jquery where the jquery overhead was what made the difference between a 20ms operation (not user-perceptible) and a 1s operation (very much user-perceptible).


Could you share your test code?




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

Search: