Crouching tiger, coding monkey

We’re gonna need a bigger boat. (Or a practical example of Apple Shark usage.)

Filed under: Apple, Profiling, Shark — Grant April 27, 2007 @ 9:40 am

Every few years we rent a beach house on a island off of North Carolina and meet up with a bunch of friends from college. During the last trip a group was off body surfing and during one of the wave breaks they noticed something that ended the surfing and started the on shore Corona drinking.

Yep, it was a shark.

Apparently it was just a little guy, only a few feet long, but there is really no bigger incentive to get out the water than one of those. Thank you very much for that Steven Spielberg.

Jaws

“Where’s all this rambling going?” you’re probably asking yourself at this point. Well, its actually a crude play on words tie-in to an application that seriously helped out yesterday.

Apple Shark

I was sitting at my desk, innocently minding my own business, when one of the TestTrack guys came over and asked if I could run a test for him. Apparently some code they were working on was running ok on Windows, only taking a few seconds, but on the Mac it was chewing up like five minutes.

WhatchyoutalkinaboutWillis? That’s not good.

A quick sanity check run showed that indeed that section was running with all the speed of a Geo Metro in a strong headwind. Dejected, the TestTrack guy started to walk off to try to find out what the heck was going on.

Me: “Hey hold on, we’ll sic the Shark on it and find out what’s up.”

TestTrack Guy: “Greg Norman?”

The Shark

Me: “No, not Greg Norman. And if you say Jabber Jaw next we’re going to have to have words.”

Jabber Jaw

So I fire up TestTrack again but this time I attach to it using Apple’s Shark profiling application. We hit the slow spot, let it crank for a little bit, then stop our sampling. Shark then chews (ha!) over the results for a minute and spits out (get it, chew, then spit out, double ha!) the timing graph of our sample. Looking down the result list things don’t seem so bad:

Result list

We keep scrolling down and notice a percentage jump between a call from our code to the Qt code. A sizable percentage jump too, we’ve found our first clue.

Percentage jump

Following the highlighted items to the right (I’ve had to cut down the screenshot to fit in this post) we see that slowdown is happening in CTTLookup::GetText. This is a method that we use get text to be rendered on the screen, which means it is called about a bazillion times.

CTTLookup

Double clicking on the CTTLookup::GetText string Shark opens up the source file with some percentage listings of how much time was spent processing on each line. Using those, and noticing in our call stack that the Qt locale code was running all over the place in Apple’s system libraries we found our slow spot.

Slow spot

Some quick refactoring to make sure that locale call only happens once instead of every call, a new compile, and presto the Mac TestTrack client is now running just as fast as the other platforms. Total time from Shark start to fixed code was probably five minutes. And we didn’t even need a shark cage, or a caddy, to do it.

1 Comment »

  1. [...] last few days I’ve been spending some quality time with my friend Shark doing a lot of performance testing. I actually kind of like that sort of work. I also have a [...]

    Pingback by Crouching tiger, coding monkey » A memory leak in the alluvial dampers — July 22, 2008 @ 12:46 am

RSS feed for comments on this post. TrackBack URI

Leave a comment