<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: JavaScript performance optimization, take 1</title>
	<atom:link href="http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/</link>
	<description>music, technology, interfaces, people</description>
	<lastBuildDate>Tue, 03 Aug 2010 22:16:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Amy</title>
		<link>http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/comment-page-1/#comment-295662</link>
		<dc:creator>Amy</dc:creator>
		<pubDate>Mon, 19 Oct 2009 16:37:14 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/?p=249#comment-295662</guid>
		<description>Hey Sho. So true about the wrapper functions and CSS selectors (and maybe some day, with wider support of getElementsByClassName, it won&#039;t be).

Especially if you are doing a lot of super-interactive user interface, you might also want to be sure that not only do you not blow away/recreate the event handlers (as you describe above), but that you use capture and bubble effectively. Hopefully you&#039;re already doing that :)

One other idea: tuning your traversals is great, but don&#039;t underestimate the extra performance suck that extra elements can cause. The more extraneous elements you can strip out, the faster everything will be. Including CSS selectors.

You might try also looking thru the other items on this JavaScript performance checklist I put out today: http://slowjavascript.com/

Nota bene: I am the co-author of JavaScript Performance Rocks! (http://jsrocks.com/), a book specifically about this very topic. It&#039;s long and very thorough, you might find it helpful. :)</description>
		<content:encoded><![CDATA[<p>Hey Sho. So true about the wrapper functions and CSS selectors (and maybe some day, with wider support of getElementsByClassName, it won&#8217;t be).</p>
<p>Especially if you are doing a lot of super-interactive user interface, you might also want to be sure that not only do you not blow away/recreate the event handlers (as you describe above), but that you use capture and bubble effectively. Hopefully you&#8217;re already doing that :)</p>
<p>One other idea: tuning your traversals is great, but don&#8217;t underestimate the extra performance suck that extra elements can cause. The more extraneous elements you can strip out, the faster everything will be. Including CSS selectors.</p>
<p>You might try also looking thru the other items on this JavaScript performance checklist I put out today: <a href="http://slowjavascript.com/" rel="nofollow">http://slowjavascript.com/</a></p>
<p>Nota bene: I am the co-author of JavaScript Performance Rocks! (<a href="http://jsrocks.com/" rel="nofollow">http://jsrocks.com/</a>), a book specifically about this very topic. It&#8217;s long and very thorough, you might find it helpful. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: keith</title>
		<link>http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/comment-page-1/#comment-295289</link>
		<dc:creator>keith</dc:creator>
		<pubDate>Tue, 13 Oct 2009 16:11:40 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/?p=249#comment-295289</guid>
		<description>Thanks for the clarification sho!

It&#039;s funny: up until I read your article I&#039;ve managed to completely neglect the fact that how the browsers handle CSS selectors may be completely different from how the popular JavaScript libraries handle them. This means that I need to start thinking more about having two different ways of optimizing CSS selectors: one for CSS statements (which are read right-to-left), and another strategy for optimizing the convenience selectors provided by jQuery, etc. Well.. guess it&#039;s time to start digging around more in the jQuery code :)</description>
		<content:encoded><![CDATA[<p>Thanks for the clarification sho!</p>
<p>It&#8217;s funny: up until I read your article I&#8217;ve managed to completely neglect the fact that how the browsers handle CSS selectors may be completely different from how the popular JavaScript libraries handle them. This means that I need to start thinking more about having two different ways of optimizing CSS selectors: one for CSS statements (which are read right-to-left), and another strategy for optimizing the convenience selectors provided by jQuery, etc. Well.. guess it&#8217;s time to start digging around more in the jQuery code :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sho</title>
		<link>http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/comment-page-1/#comment-295113</link>
		<dc:creator>sho</dc:creator>
		<pubDate>Sat, 10 Oct 2009 16:00:43 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/?p=249#comment-295113</guid>
		<description>Thanks for that info, Jay. Good to know.</description>
		<content:encoded><![CDATA[<p>Thanks for that info, Jay. Good to know.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay Freeman (saurik)</title>
		<link>http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/comment-page-1/#comment-295100</link>
		<dc:creator>Jay Freeman (saurik)</dc:creator>
		<pubDate>Sat, 10 Oct 2009 12:11:30 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/?p=249#comment-295100</guid>
		<description>In point of fact, Opera 9.5, Safari 3.1, Chrome, and Firefox 3 all provide native implementations of getElementsByClassName, as specified by HTML5. Hopefully your JS library is taking advantage of this, but given your performance figures I can only assume it isn&#039;t. It is incredibly unfortunate how much worse the state of browser performance is due to popular libraries refusing to take advantage of browser-specific features, no matter how commonly implemented. For the record, I believe JQuery finally changed their policy on this matter, which may be another reason to switch to it.</description>
		<content:encoded><![CDATA[<p>In point of fact, Opera 9.5, Safari 3.1, Chrome, and Firefox 3 all provide native implementations of getElementsByClassName, as specified by HTML5. Hopefully your JS library is taking advantage of this, but given your performance figures I can only assume it isn&#8217;t. It is incredibly unfortunate how much worse the state of browser performance is due to popular libraries refusing to take advantage of browser-specific features, no matter how commonly implemented. For the record, I believe JQuery finally changed their policy on this matter, which may be another reason to switch to it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sho</title>
		<link>http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/comment-page-1/#comment-295080</link>
		<dc:creator>sho</dc:creator>
		<pubDate>Sat, 10 Oct 2009 02:33:53 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/?p=249#comment-295080</guid>
		<description>Ah. I forgot to mention why I tried that.

The selectors module in mootools (and I imagine jquery) splits apart the selector into multiple parts and performs the fastest actions first.

If the selector contains an id, the element is recovered using the low level DOM method getElementById(). 

If the selector contains a tag, the list of candidate elements is computed using the low level DOM method getElementsByTagName().

If neither a tag nor an id are provided, the entire subtree must be searched.

For classes and pseudo elements, there is no low-level DOM call to find these, so each element must be checked one by one using JavaScript.

Adding the class to the selector thus helps speed things up by narrowing the list of tags to search through via a quick DOM call.</description>
		<content:encoded><![CDATA[<p>Ah. I forgot to mention why I tried that.</p>
<p>The selectors module in mootools (and I imagine jquery) splits apart the selector into multiple parts and performs the fastest actions first.</p>
<p>If the selector contains an id, the element is recovered using the low level DOM method getElementById(). </p>
<p>If the selector contains a tag, the list of candidate elements is computed using the low level DOM method getElementsByTagName().</p>
<p>If neither a tag nor an id are provided, the entire subtree must be searched.</p>
<p>For classes and pseudo elements, there is no low-level DOM call to find these, so each element must be checked one by one using JavaScript.</p>
<p>Adding the class to the selector thus helps speed things up by narrowing the list of tags to search through via a quick DOM call.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: keith</title>
		<link>http://kuwamoto.org/2009/10/09/javascript-performance-optimization-1/comment-page-1/#comment-295079</link>
		<dc:creator>keith</dc:creator>
		<pubDate>Sat, 10 Oct 2009 02:24:39 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/?p=249#comment-295079</guid>
		<description>Thanks for the tips :) I&#039;m a little suprised that selecting for div.class over .class would improve performance. I used to think that selectors worked left to right, and by being more specific, it would make it easier on the browser. There was an article by Steve Souders (http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/) not too long ago, however, which mentioned that selectors are matched from right to left though. Since that&#039;s the case, wouldn&#039;t it be quicker to just match .class instead of div.class?</description>
		<content:encoded><![CDATA[<p>Thanks for the tips :) I&#8217;m a little suprised that selecting for div.class over .class would improve performance. I used to think that selectors worked left to right, and by being more specific, it would make it easier on the browser. There was an article by Steve Souders (<a href="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/" rel="nofollow">http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/</a>) not too long ago, however, which mentioned that selectors are matched from right to left though. Since that&#8217;s the case, wouldn&#8217;t it be quicker to just match .class instead of div.class?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
