Javascript Profiler

I’ve recently been working on a cross-browser javascript profiler I call jsprofile. It’s finally beginning to take shape. The main idea was to be able to profile javascript in IE in addition to Firefox, as Firefox already has the excellent Firebug extension going for it. The main driver for wanting to profile in IE was the desire to analyze performance of the ajaxslt library’s XPath evaluation.

I ran a brief test using the same XPath I’ve been using for a while, on a snapshot of the Google News page, comparing IE7 against Firefox2. I used ajaxslt 0.8 . The results are quite interesting, download here in OpenOffice format: Ajaxslt Profiling Results

If my profiling results are correct (I acknowledge more rigor is possible (the “a script is running for a long time” dialog popped up several times when I was profiling IE7, taking some time to dismiss), but I just wanted to perform a quick test), several important trends are evident.

First, IE7 is way way slower than Firefox. But we knew that. ;)

Second, the results don’t equivocate about which method calls are taking the longest. The top four worthy of consideration for optimization are (in order of total time consumed): xPathStep, ExprContext, BooleanValue, and copyArray.

Third, the average own time for xPathStep is grossly larger in IE than in Firefox; 5.18ms, versus only 0.22ms.

Finally, perhaps the most surprising result is that the number of method calls differed on the browsers, even though the XPath used was exactly the same. Shockingly, both ExprContext and BooleanValue had 20x more invocations in IE! Are these extra calls really necessary? Are they an artifact of my still-maturing profiler code? I hope we can determine the potential for optimization here is real. :)

Update

It appears that the profiler (not surprisingly) misses a few key methods: compare, clone, and evaluate. I’ll have to look into it more, but my hunch is that these are either added dynamically or are added to object prototypes, which the profiler currently may not be able to detect. Out of curiousity, I profiled the profiler itself running the ajaxslt test, using Firebug. This is what revealed the missing methods, whose timings are likely the main contributors to xPathStep.

It was interesting to observe the average time for the profile entry and exit functions. Obviously, these can impact the accuracy of the results. The average time for both added together was about 0.02ms . In comparison, the average times for compare, clone, the longest running evaluate (there are several), and copyArray were 0.463ms, 0.048ms, 0.573ms, and 0.03ms, respectively.

I’ll see if I can get the profiler to automatically capture those missing methods. I’ve added the Google News test to the repository, so you can try it and see for yourself.

Leave a Reply


Bad Behavior has blocked 824 access attempts in the last 7 days.