Today I was profiling the initialization time of RadTreeView for ASP.NET Ajax and found out that the biggest bottleneck was traversing the DOM tree. The code looks something like this:
I tested with 10000 elements and in IE7 I got about 25000ms whilst in FireFox the total time was around 33ms (Core 2 Duo @ 2.33GHz). Quite a difference if you ask me.
I thought that there may be some IE specific method/property which could perform better and I dug into MSDN. And a few minutes later I found the children property!!! Apparently the children collection contains only HTML elements (whilst childNodes is full of TextNode elements). I changed the code like this:
Lo and behold the total traverse time went down to around 30ms in IE7 !!! This is what I call a performance boost :)
To make it cross-browser friendly I ended up with this:
The bottom line is that you can expect some serious performance improvements in treeviews with lots of nodes. For example the initialization time of a fully expanded treeview with 10000 (10x10x10x10) nodes improved by 30% (3152ms vs. 2249ms). However if the total number of nodes per level is greater e.g. 10x1000 the performance boost is even bigger - 5590ms vs. 1851ms which is 66%.
I have attached a sample page with tests using unordered list with 10000 list items.
Iana Tsolova is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.