> While playing around with your example though, I found that in a more
> 'practical' loop, like 1-4, Slick is actually much faster (running
> Chrome).
If you're still using the tiny test XML, that's still not "practical."
The high number of iterations was one way to amplify the performance
differences. The other way is to use a real XML file of some depth and
breadth and run with far fewer iterations.
Here we only run 100 times over a 256K XML file.
http://jsfiddle.broadleafsystems.com/FrTQc/41/show/light/
The differences are very dramatic, it's not wasting single-digit
milliseconds in this scenario but rather almost 1 to 5 full _seconds_.
In my FF, I get 0-1ms times for native getElementById yet ~1 second
times for Slick. In IE, it's 500ms times for native selectSingleNode
and ~6 seconds for Slick!
So I don't consider it premature nand/nor micro-optimization.
Especially when you take JS' single-threading model into account. It's
unlike other deployments where slow-running code can be left to crawl
along, or even lock up one CPU leaving other CPUs free. An
optimization that would be crazy-talk in a traditional desktop
environment can be quite reasonable in the browser.
And consider web apps that use XML as a "data island" to frequently
run complex lookups against the same doc, say online spreadsheets and
suchlike (after all, if we have a need for getElementById outside of
the DOM at all, the implication is that XML is not being used simply
as an opaque transport mechanism for HTML tags). I wouldn't want to
know I'm spending 70ms per lookup if I can get it down to 5ms pretty
easily.
True, you could make the point that optimization is unnecessary you're
just running getElementById a couple of times over the page's
lifetime. But even in a one-page site I just built, I pull in like 200
records over XML and query across them before insertion (because I
have to massage certain stuff as I don't own the back end). I wish I
could be assured of the best performance possible.
-- S.