Performance Statistics Without the Leak

About a month ago I was helping a friend pinpoint a memory leak in a Flex application. Remember Alice in Wonderland? Yes... the rabbit-hole goes deeper.

We found the source of the leak - a crazy child to parent event listener which we refactored; everything was behaving now as expected. Just a few minutes later I saw a tweet from G.Skinner which included a link to a Google Code project called Hi-Res! Stats by Mr.doob. It piqued my interest so I decided to give it a look-see.

I launched a profiling session... and right away noticed the memory footprint going up and down... leak... up and down... leak... up and down... leak... anyone sea sick yet?

It wasn't much, but the thought crossed my mind - of all things that should behave in a performance tuning context this should! To confirm my findings I created a new / empty project that contained the Stats and nothing but the Stats.

Yep... there it was again - and there was nothing else in the project to blame the behavior on. With a little digging I stumbled on a series of oh-so-nice issues in the Adobe Bug Base. So... I decided to see if I could get Hi-ReS! to behave.

One of the key discoveries in my experiment was that anything beyond using the Flash drawing API in frame/render handlers caused ripples in the memory footprint. Yes, that would include touching objects of any kind - getting text into the mix was going to be interesting. I'll talk about that in a minute...

What was I seeing during a profile session? Something like this... notice the oatmeal lumps? Like I said... if there is anything that should play nice in a performance monitoring context - it's things like this. Naughty stats! Naughty...

Fast forward a couple hours - and I was able to flatten things out.

Did the quality of the output suffer? Compare the output of Hi-ReS! Naughty Stats...

...to Hi-ReS! Nice Stats. Looks like I haven't broken anything - let me know if I have.

Yeah... I know my stats implementation has fuzzy text and I moved some of the items around. Each of those changes was needed to plug a leak or smooth out the flow of things. Sorry - sometimes compromise leads to a loss of resolution.

Final note, you should take a look at the text drawing stuffs - it's an interesting approach to programmatic text using a multi-segment display for inspiration.

[ source / example: Hi-Res! Stats Redux ]