Welcome!

AJAX & REA Authors: RealWire News Distribution, Kevin Benedict, Lori MacVittie, Alois Reitbauer, Andreas Grabner

Related Topics: AJAX & REA, Java, SOA & WOA

AJAX & REA: Article

How Bad Outdated JavaScript Libraries Are for Page Load Time

Make sure you stay up-to-date with your library versions.

Last week at Velocity we hosted a Birds of a Feather Session (BoF) and offered the attendees to analyze their web sites using dynaTrace Ajax Edition. Besides finding the typical performance problems (no cache settings, too many images, not minimized content, …) we found several sites that had one interesting problem in common: OLD VERSIONS of  JavaScript libraries such as YUI, jQuery or SPRY.

Why are outdated JavaScript Libraries a problem?
JavaScript libraries such as jQuery provide functions that make it easy for web developers to achieve certain things, e.g.: change the style of certain DOM elements. Most of these libraries therefore provide methods called $, $$ or find that allow finding DOM elements by ID, Tag Name, CSS Class Name or specific DOM attribute values.

The following is a screenshot of the Performance Report analyzing the Boston Bruins Page on msn.foxsports.com using Firefox 3.6. The Performance Report highlights 3 interesting things:

  • High Client Time (3.5 seconds in JavaScript execution until the Page was Fully Loaded)
  • 39 JavaScript! blocks that executed longer than 20ms
  • 38 calls to Spry.$$ for looking up an element by Class Name with an average of 80ms execution time
Long running CSS Class Name Lookups contribute about 80% to the Client Side Load Time

Long running CSS Class Name Lookups contribute about 80% to the Client Side Load Time

Looking up elements by class name takes 80ms on average. We see 38 calls with a total JavaScript execution time of 3 seconds. Is that normal? Even on Firefox?

The History on CSS Class Name Lookups
Looking up elements by CSS Class Name is a very popular lookup method. Browsers such as Firefox or Chrome supported this lookup natively with a method called getElementsByClassName. Older versions of Internet Explorer don’t support this.

The lack of this native implementation in IE caused many JS libraries to implement this missing feature using JavaScript. The implementations traverse through the complete DOM Tree and perform a string match on the CSS Class Name property. This works well and allows web developers to use one library that works across all browsers and browser versions. The down side of this approach is that traversing the DOM is one of the slowest operations you can do in the browser. The larger the DOM, the longer these lookup methods take to execute. I’ve blogged about this several times: 101 on jQuery Selector Performance, 101 on Prototype CSS Selectors, Top 10 Client-Side Performance Problems.

Good news is that newer versions of Internet Explorer now support the Selector API allowing JavaScript frameworks to leverage this native implementation and with that optimizing lookup performance.

Why is Spry.$$ so slow on Firefox?
Let’s get back to our example from above. We learned that newer browsers support lookups by class name natively and we also learned that Firefox, Chrome, Safari, Opera, …  had the native lookup methods implemented for a while. Does this mean that 80ms for looking up elements by class name is normal? No – it is not!! It should take a fraction of that. And here is why.

The following screenshot shows the JavaScript PurePath of Spry.$$(“.prev_label”). The PurePath shows us what happens internally in this method and why it takes 170ms for that call to complete:

Spry.$$ iterates through all DOM Elements and matches the CSS Class Name

Spry.$$ iterates through all DOM Elements and matches the CSS Class Name

Instead of leveraging the native getElementsByClassName method of Firefox the implementation of Spry.$$ uses its own implementation. Using getElementsByTagName with no specific tag name returns ALL DOM Elements – 2787 in total on that page. The library then iterates through all of these DOM elements, reading the className DOM Property and matching it against “prev_label”. Accessing 2787 DOM Properties is a costly operation and takes 170ms in that instance. That’s why Spry.$$ takes that long.

Solve this problem by upgrading your Libraries
Older versions of JavaScript libraries didn’t necessarily check the browsers capabilities for looking up DOM Elements. These libraries always used their own implementation. Newer versions of libraries do check the capabilities and take advantage of any performance enhancement they can get by using the native available implementations.

On this particular website – and also the others we looked at during the BoF session – an older version of the JavaScript library was used. Upgrading to a newer version would solve this problem. I know – upgrading is not always as easy as it sounds. Lots of testing is involved to ensure that your web site still works as expected. On the other side – speeding Page Load Time by 3 seconds by “just” updating your JavaScript library is a good argument in doing so.

Conclusion
Make sure you stay up-to-date with your library versions. Library providers are focusing a lot on performance and they make sure to optimize these libraries for the different browsers out there.

Tips and Tricks
The dynaTrace Performance Report identifies slow running JavaScript handlers and also identifies the jQuery $ method. In the case of Spry.$$ (or maybe other lookup methods that your library provides) the report won’t list these methods in the Contributor list. A little trick helps though to identify how much performance impact these methods have on your page. Simply Drill into the Hotspot View. Then type “Spry.$$” and sort by Total Sum. This will show you all invocations of Spry.$$ and how much time it takes to execute them:

Analyzing your JavaScript Lookup methods in the Hotspot View

Analyzing your JavaScript Lookup methods in the Hotspot View

Learn how to use the different views and features of dynaTrace Ajax Edition by watching the 15 available Video Tutorials

Related reading:

  1. Slow Page Load Time in Firefox caused by old versions of YUI, jQuery, … We blogged a lot about performance problems in Internet Explorer...
  2. Uncover JavaScript JSON Parsing errors with IE Compatibility Mode We just launched our new corporate web site. Right after...
  3. Testing and Optimizing Single Page Web 2.0/AJAX Applications – Why Best Practices alone don’t work any more // Testing and Optimizing of what I call “traditional” page-based...
  4. Top 10 Client-Side Performance Problems in Web 2.0 Inspired by the Top 10 Performance Problems post which focuses...
  5. Antivirus Add-On for IE to cause 5 times slower page load times The dynaTrace AJAX Community has been really active lately –...

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

Cloud Expo Breaking News
With virtualized workloads proliferating widely, the nature of management and optimization tools will need to undergo a dramatic change. Platforms and best practices that perform intelligent scheduling of workloads across virtual machines, as well as diligent provisioning and de-provisioning of VMs to control VM sprawl, will be crucial to ensure maximum performance and utilization of infrastructure. In his session at the 9th International Cloud Expo, James Thomason, Chief Architect at Gale Tec...
Data motility is the concept that data in the cloud is not just mobile, but can move on its own without administrators’ knowledge or consent. Enterprise agreements with cloud vendors specify that information placed in the cloud will be available when a company wants it – but not where it is living from one moment to the next. In his session at the 9th International Cloud Expo, Dave Asprey, VP of Cloud Security at Trend Micro, will address the important concerns that this “always available from...
Google and Microsoft are in a battle for the hearts and minds of corporations worldwide. You and your company can benefit from this battle...if you are Cloud-Ready. In his session at the 9th International Cloud Expo, Jason Lieblich, Founder and CEO of Exoprise Systems, will discuss how you can arm your organization with the right data, tools and systems to manage this transition to the cloud. This battle will define the computing landscape for decades to come. Be prepared!
The July 29 deadline for the Call for Papers for the 9th International Cloud Expo, to be held November 7-10, at the Santa Clara Convention Center in Santa Clara, CA, is fast approaching. As enterprises in ever-increasing numbers start to evaluate cloud computing, many are assessing which applications can run in public clouds, which should run in a private cloud, and how to ensure that applications will be portable from one to another. Since there will be many different kinds of clouds, another ...
Performance problems are one of the most cited concerns about the cloud. But is it really the cloud or the application? What does performance mean anyway when you can scale to thousands of servers? In his session at the 9th International Cloud Expo, Michael Kopp, Technology Strategist at dynaTrace Software, will discuss why the traditional means of performance management and troubleshooting no longer work and how this affects everything. Most important, we will look at how to identify the root...
Due to a paradigm shift in developing the latest wave of mobile applications, to use the existing or "old" approach to mobile development has significant limitations. In his session at the 9th International Cloud Expo, Fima Katz, President & CEO of Exadel, will discuss a new, quite revolutionary way of building the next-generation mobile cloud applications. In this approach everything, from development platform to deployment to resources, resides in the cloud. The underlying platform (PaaS) al...
Simplifying and automating IaaS provisioning helps companies slash costs with shared dynamic environments while sustaining workload performance expected in dedicated environments. Will 2012 be the year when enterprises fully embrace their heterogeneous environments to get the best of both cloud worlds, while using legacy IT equipment to build dynamic clouds running virtualized and non-virtualized workloads? In his session at the 9th International Cloud Expo, Akhil Sahai, VP of Product Manageme...
Cloud computing is commonly described in terms of service-style access: "Infrastructure as a Service" (IaaS), "Platform as a Service" (PaaS), and "Software as a Service" (SaaS) are popular monikers attached to different styles of cloud computing. In the enterprise, however, it is often better to consider an alternative view in which services themselves are part of the infrastructure. In his session at the 9th International Cloud Expo, Dr. Rich Wolski, CTO and Co-founder of Eucalyptus Systems I...
SYS-CON Events announced today that Vyatta, the leader in software-based networking for physical, virtual and cloud infrastructures, will exhibit at SYS-CON's 9th International Cloud Expo, which will take place on November 7–10, 2011, at the Santa Clara Convention Center in Santa Clara, CA. Vyatta is disrupting the networking industry by delivering a software-based network operating system that is portable to standard x86 hardware as well as common virtualization and cloud computing platforms. ...
Evolutionary IT organizations are taking a measured path to cloud, virtualizing and automating along the way. Other IT organizations are following the “fast track,” meeting limited user needs with Cloud Pilot implementations. This session is a dynamic exploration of the benefits (and challenges) that diverse IT service adoption cultures will experience. Transformational cloud projects seek to overhaul IT to align with this more flexible and responsive paradigm, starting with a comprehensive visi...