<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
  <channel>
    <title>ASP.NET AJAX: Replacement CSS add/remove functions</title>
    <link>http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</link>
    <atom:link href="http://www.lotterypost.com/rss/blogcomments/25857" rel="self" type="application/rss+xml" />
    <description>Speednet's Blog: ASP.NET AJAX: Replacement CSS add/remove functions</description>
    <dc:language>en-us</dc:language>
    <generator>Lottery Post RSS Generator</generator>
    <item>
      <title>Comment #3</title>
      <link>http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</guid>
      <pubDate>Wed, 13 Jan 2010 01:16:15 GMT</pubDate>
      <dc:creator>Bleroy</dc:creator>
      <description><![CDATA[Thanks for the feedback. I'll be sending this to the Ajax team. One thing that looks weird though is that you'd have type checking in there. If you run the scripts in release mode, no such check should happen.]]></description>
      <category>Bleroy</category>
    </item>
    <item>
      <title>Comment #2</title>
      <link>http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</guid>
      <pubDate>Sun, 18 Jan 2009 21:11:36 GMT</pubDate>
      <dc:creator>Todd</dc:creator>
      <description><![CDATA[Thanks for the comment Ben.

Using a RegExp in containsCssClass would probably slow it down a little, not only in the execution speed of the test, but also when the JavaScript parser dynamically creates and compiles the regular expression.  

When I am building a string-manipulation function strictly for speed, those are the types of things I try to anticipate.  Regular expressions can be a double-edged sword, in that they can be incredibly flexible and even easy to use (when you've grown ac... [&nbsp;<a href="http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm">More</a>&nbsp;]]]></description>
      <category>Todd</category>
    </item>
    <item>
      <title>Comment #1</title>
      <link>http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</guid>
      <pubDate>Tue, 02 Dec 2008 18:24:38 GMT</pubDate>
      <dc:creator>Ben Amada</dc:creator>
      <description><![CDATA[Nice improvements.  15 seconds down to 1 second is terrific.  I wonder if there would be any measureable difference if your containsCssClass() function used a regexp too.]]></description>
      <category>Ben Amada</category>
    </item>
    <item>
      <title>Original Blog Entry: ASP.NET AJAX: Replacement CSS add/remove functions</title>
      <link>http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm</guid>
      <pubDate>Fri, 28 Nov 2008 07:15:05 GMT</pubDate>
      <dc:creator>Speednet</dc:creator>
      <description><![CDATA[<p>I came across a major performance issue in the Microsoft ASP.NET AJAX client library (JavaScript library) today.</p><p>Because the nature of the issue is engrained in the client library code, the only way around it was to completely abandon use of the functions that add, remove, and test for the existence of class names assigned to DOM elements, and develop my own.</p><p>Specifically, the following functions are involved/affected:</p><ul><li><span style="font-family: Courier New,Courier,monospace;">Sys.UI.DomElement.addCssClass</span></li><li><span style="font-family: Courier New,Courier,monospace;">Sys.UI.DomElement.removeCssClass</span></li><li><span style="font-family: Courier New,Courier,monospace;">Sys.UI.DomElement.containsCssClass</span></li><li><span style="font-family: Courier New,Courier,monospace;">Sys.UI.DomElement.toggleCssClass</span></li></ul><p>In program code that changes only a few classes here and there, nobody would ever notice performance problems, but when iterating over a large set of DOM elements&nbsp;.... well, that's a different story.</p><p>In the process of investigating the performance issues, I took a look at the code behind those functions.&nbsp; I didn't do a bunch of stand-alone, isolated tests to prove my theory (because frankly I don't have the time to do it!), but I believe the problem lies in the <span style="font-family: Courier New,Courier,monospace;">containsCssClass</span> function.&nbsp;</p><p>Internally, almost every other CSS function calls <span style="font-family: Courier New,Courier,monospace;">containsCssClass</span>, so because <span style="font-family: Courier New,Courier,monospace;">containsCssClass</span> has a performance issue, it ripples through the other functions as well.</p><p>The <span style="font-family: Courier New,Courier,monospace;">containsCssClass</span> function does a lot of unncessary work just to find out if a particular element contains a specific class name.&nbsp; It performs a JavaScript <span style="font-family: Courier New,Courier,monospace;">split</span> call on the string, then goes through the newly-created array one element at a time to look for a match.&nbsp; But in doing that, it makes various function calls, performs redundant <span style="font-family: Courier New,Courier,monospace;">typeof</span> checks &mdash; and performs a <em>case-sensitive</em> test on the class name!</p><p>So if you perform many....</p><p>[ <a href="http://blogs.lotterypost.com/speednet/2008/11/aspnet-ajax-avoid-using-css-addremove-func.htm">More</a> ]</p>]]></description>
      <category>* Original Blog Entry</category>
      <wfw:comment>http://www.lotterypost.com/blogentry/25857</wfw:comment>
    </item>
  </channel>
</rss>
