| By Andreas Grabner | Article Rating: |
|
| November 23, 2009 01:00 PM EST | Reads: |
4,502 |
RIA Developer's Journal on Ulitzer
In my previous article I talked about the impact of jQuery Selectors on a page that I analyzed. The page took 4.8 seconds in the onLoad event handler. 2 seconds were mainly caused by the selectors as described in the blog. The other 2.8 seconds were caused by a dynamic JavaScript menu - in that particular case it was the superfish jQuery plugin. A closer analysis showed why it takes so long and this also got me to do some research on these menus. Kudos to Joel Birch for his excellent plugin - easy to integrate - and - if properly used - its fast enough.
2.8 seconds for superfish menu - why?
The following image shows the PurePath for the onLoad event handler captured by dynaTrace AJAX Edition. It also shows the JavaScript source code that selects the ".nav" element and invokes the superfish method on this object. As a result we see the superfish method iterating through each anchor tag (544 on that web page) performing the necessary DOM manipulation on each element to transform the list elements and anchors in a dynamic menu:

dynaTrace AJAX PurePath showing superfish execution on a 544 element menu
For each anchor tag - superfish performs some actions. As you can see from the code-snippet of the for-each function - the $a.eq(i) could be replaced with a $(this). This alone would save about 20% of performance.
The real problem here however is not necessarily the superfish implementation. It is a huge menu structure with 544 menu items. I am not sure how many web pages exists that use very large menus like this - but I am sure there are. The problem with the approach on this web page is that the page is unresponsive for several seconds giving the end-user a bad end-user experience. Delay loading the JavaScript - using timers to not block the browser - smaller menus - ... - all these are probably valid options to speed up this page. Any additional suggestions out there?
Performance Analysis of different Menu Sizes
Based on this superfish example I created a sample page with 3 different sized menus: 50 elements, 100 elements and 500 elements. The page has 3 buttons - each triggers the menu creation and makes the correct menu visible. Here is an example for the small menu:

Sample Page with a small dynamic Menu
Analyzing the execution times it takes for each menu size shows me that the superfish menu scales really well - it is just that you have to be careful with the number of elements. Here are the results for 50, 100 and 500 menu items:

Performance Analysis of 50, 100 and 500 menu items
Conclusion
DOM Manipulations are expensive. The more elements you have to manipulate the more overhead you will see. Dynamic menus are a great way to make your website more interactive and nicer to navigate through - but keep in mind the cost of every menu item. This is just one example of a dynamic menu library - there are tons of other implementations out there. Any feedback in terms of performance or best practices on this or other libraries?
Published November 23, 2009 Reads 4,502
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Andreas Grabner
Andreas has over a decade of experience as an architect and developer, and currently works as a senior performance architect and technology strategist for dynaTrace Software, where he influences product strategy and works closely with customers in implementing performance management solutions across the application life cycle. He is a regular speaker at software conferences, writes for a number of technology publications, and blogs at http://blog.dynatrace.com
- Ubuntu-based Open Source Linux Mint Tests KDE Version
- Linux Virtualization and Tired Open Source Myths
- IGEL Supports Red Hat Enterprise Virtualization 3.0
- CloudLinux Announces Support for Atomia
- Jury Gets Novell Antitrust Case Against Microsoft
- SPIRIT DSP Receives 2011 INTERNET TELEPHONY Product of the Year Award
- Amazon Kindle Fire Gets Its Own 'Personal Cloud Desktop' with AlwaysOnPC App Launch
- Hadoop Quickstart: Use Whirr to automate standup of your distributed cluster on Rackspace
- The Utility Infrastructure Security Market 2012-2022: Cybersecurity & Smart Grids
- FORTUNE Magazine Names Rackspace Among “100 Best Companies to Work For”
- Convirture Reports Strong 2011 as Virtualization Management Takes Off
- iFollowOffice Turns to Virtual Bridges and Savvis for On-Demand Virtual Desktop Services
- i-Technology in 2012: Five Industry Predictions
- Ubuntu-based Open Source Linux Mint Tests KDE Version
- Amazon to Rent Out Supercomputers
- Amazon Émigré Starts Network Monitoring Firm
- HP’s Putting a Back Door in the Itanium Alamo
- Linux Virtualization and Tired Open Source Myths
- CloudLinux Announces Preferred Partner Program
- MapR Pushes the Hadoop Envelope
- Rightware Announces Gaming Performance Benchmark for OpenGL ES 3.0/Halti
- IGEL Supports Red Hat Enterprise Virtualization 3.0
- CloudLinux Announces Support for Atomia
- 3Dconnexion Announces its Newest 3D Mouse - the SpaceMouse Pro
- The i-Technology Right Stuff
- Linux.SYS-CON.com Exclusive: Linus Discloses *Real* Fathers of Linux
- After Ubuntu, Windows Looks Increasingly Bad, Increasingly Archaic, Increasingly Unfriendly
- A Closer Look at Damn Small Linux
- Linus' Top Ten SCO Barbs
- SCO CEO Posts Open Letter to the Open Source Community
- Netscape Co-Founder's 12 Reasons for Growth of Open Source
- Where Are RIA Technologies Headed in 2008?
- *POINT - COUNTERPOINT SPECIAL* What's Wrong with the Open Source Community?
- Introducing "Cooperative Linux" - Linux for Windows, No Less
- Linux.SYS-CON.com Exclusive: What Would UserLinux Look Like?
- Why Recovering a Deleted Ext3 File Is Difficult . . .
















