Microsoft Cloud Authors: Nick Basinger, Kevin Benedict, Pat Romanski, Liz McMillan, Lori MacVittie

Related Topics: Microsoft Cloud, Machine Learning

Microsoft Cloud: Article

Garbage Collection in IE7

GC in IE7 is heavily impacted by number of JavaScript objects and string sizes

After my recent presentation at TSSJS – Performance Anti-Patterns in AJAX Applications - I got interesting feedback from one of the attendees: “The presentation was good but I thought you are talking more about actual problems with XHR/AJAX Requests”. I have to admit that I focused on all common problems of Web 2.0 applications – including network roundtrips, JavaScript and Rendering – and not just on those related to asynchronous communication. The comment made me work on a sample application where I want to test different approaches of asynchronous data processing that I’ve seen when working with our user base. I ran into a very interesting performance problem that I didn’t anticipate. So – before I write about the actual different approaches (XML vs. JSON, XHR vs. script tags, …) I want to share a performance problem in IE 7’s JavaScript engine that everybody should be aware of.

The more “active” JavaScript objects the slower your string manipulations

In my sample I process 1000 contact objects from two different data sources: XML and JSON. In case of XML I read element by element – create a JavaScript object and pass it to a method that appends the object’s content to a string buffer which will later be displayed on the page. In the JSON case I load all 1000 objects at once into an array and then hand each object to the same method by simply iterating over the array elements. Here is the pseudo code for my XML use case:

foreach(xmlElement in allXmlElements) {
var jsonObject = {};
jsonObject["firstName"] = xmlElement.getValueOf("firstName");
jsonObject["lastName"] = xmlElement.getValueOf("lastName");

And the pseudo code for JSON:

var allJsonObjects = eval(jsonObjectsAsString);
foreach(jsonObject in allJsonObjects) {

processObject itself is simply concatenating the individual properties of the JSON Object to a global string variable:

globalString += jsonObject.firstName + " " + jsonObject.lastName + ...

Running this example on Internet Explorer 7 is SLOW

I assumed that the 2nd use case (JSON) is much faster than the first as I assumed that iterating through the XML DOM is slower then parsing a string of JSON. Well, this assumption was correct (parsing through the XML is slower than parsing JSON), but the string concatenation in processObject turned out to be much slower in the JSON use case as compared to the XML use case.
Analyzing the JavaScript execution with the FREE dynaTrace AJAX Edition shows me all the 1000 invocations of processObject in both use case scenarios. In both cases execution time of the method increases over time – that is explained by a growing globalString object which gets more expensive to manipulate the larger the string grows. By the way, I know there are better ways to concatenate strings, and I should try out some of these recommendations. An excellent read here are the blogs from the guys at SitePen, e.g.: String Performance: An Analysis or String Performance: Getting Good Performance from Internet Explorer.

Let’s look at my results side-by-side showing the average execution time of processObject as well as the first couple of calls and the last couple of calls of the overall 1000 invocations of that method:

Execution Time Comparison between my two scenarios

Execution Time Comparison between my two scenarios

The left execution trace shows the JSON example where I constantly have 1000 JavaScript objects in memory (300ms). The right shows the XML example where I only have 1 JavsScript object in memory (150ms). The processObject method is called 1000 times in both scenarios and is doing exactly the same thing – concatenating the individual properties of the passed JavaScript object to a global string. The difference in execution time of these string concatenations, however, changes dramatically the longer the string gets. The only explanation I have for this “phenomenon” is that IE’s Memory Management is impacted greatly by having the additional 1000 JavaScript objects in memory (see my detailed analysis below the next image).

I copied the 1000 execution times of processObject for both use cases into an excel spreadsheet and graphed the timings. It’s interesting to see how the exec times change over time with an interesting spike at about 800 times the method was invoked:

JavaScript execution time over time

JavaScript execution time over time

The blue line shows the execution time of the scenario where I have the 1000 additional JavaScript objects in memory. The pink line shows the times with only 1 custom JavaScript object in memory. There are two interesting observations here – and I hope some of you (my fellow readers) can share your thoughts on it and correct me if my conclusions are incorrect: We see an increased exec time at the very beginning and a jump in execution time after about 800 executions of this method. I assume it has to do purely with the Garbage Collection and Object Allocation strategy of IE. Daniel Pupius’ blog about Garbage Collection in IE6 gives some answers on when IE kicks of the GC (after 256 variable allocations, 4096 array slot allocations and 64kb of String allocations). I am sure Microsoft has changed the GC strategy for IE7 but Daniel’s blog definitely explains the spike in my graph. My string size ends up being 79k. After about 800 executions it crosses the 64kb limit. Interesting is that from that point on I have constantly high execution times. So – the GC always runs when you have strings larger than 64kb!! I explain the individual smaller spikes with the GC runs triggered by 256 variable allocations. What I can’t explain is the much higher execution times in the very beginning – any thoughts?

Key takeaway: Be careful with string allocations and objects in memory -> GC in IE7 performs really badly

Running this example on IE8, FireFox and Chrome is FAST

I ran the same example on Internet Explorer 8, FireFox 3.6 and the latest version of Chrome. Not surprisingly the execution time on all of these latest versions of these browsers where between 2 and 15ms. These timings were the same for both use case scenarios (1 and 1000 objects in memory). Chrome and FireFox were in fact the fastest with only 2ms of execution time. IE8 took 15ms. The following graph shows the comparison between the tested browsers:

String Concatenation Times across Browsers

String Concatenation Times across Browsers


First of all – here is the actual sample I used. Click on the 1000 Objects and 1000 Objects (wArray). Test it on your machine and let me know if you experience any different behavior. I am also very happy to accept any recommendations on how to speed up this sample – I am sure there are many ways of doing so.

Second – it is important to understand the browsers internal memory management and the GC strategies. IE 7 will be here for a long long time so be careful with your object allocations. It also shows how important it is to test and analyze performance across browsers – especially on Internet Explorer. Most developers that I meet don’t use IE at all and purely focus on FF, Chrome or Safari. This often leads to the fact that problems like this here won’t show up until late in the project (when testers are testing the software across browsers and platforms) or when the page hits “The Real User” who happens to use IE quite a lot.

Third and final conclusion – I hope this was helpful. As always – if you are interested in more information check out some of the other AJAX Related blogs and watch some of the webinars we recorded with our clients, e.g.: the one I did with Monster.com.

Related reading:

  1. .NET Performance Analysis: A .NET Garbage Collection Mystery Memory Management in .NET is a broad topic with a...
  2. Week 8 – Challenges in Tracing JavaScript Performance by Example In an earlier post I already discussed several approaches towards...
  3. Performance Analysis of dynamic JavaScript Menus In my previous post I talked about the impact of...
  4. Performance Analysis: How to identify “bad” methods messing up the GC Whenever the Garbage Collector kicks in to free up memory...

More Stories By Andreas Grabner

Andreas Grabner has been helping companies improve their application performance for 15+ years. He is a regular contributor within Web Performance and DevOps communities and a prolific speaker at user groups and conferences around the world. Reach him at @grabnerandi

IoT & Smart Cities Stories
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Cell networks have the advantage of long-range communications, reaching an estimated 90% of the world. But cell networks such as 2G, 3G and LTE consume lots of power and were designed for connecting people. They are not optimized for low- or battery-powered devices or for IoT applications with infrequently transmitted data. Cell IoT modules that support narrow-band IoT and 4G cell networks will enable cell connectivity, device management, and app enablement for low-power wide-area network IoT. B...
The hierarchical architecture that distributes "compute" within the network specially at the edge can enable new services by harnessing emerging technologies. But Edge-Compute comes at increased cost that needs to be managed and potentially augmented by creative architecture solutions as there will always a catching-up with the capacity demands. Processing power in smartphones has enhanced YoY and there is increasingly spare compute capacity that can be potentially pooled. Uber has successfully ...
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...