Dev Dawn

May 4, 2006

Capesoft Profiler - OMG!

Filed under: Uncategorized — @ 11:33 pm

Those that know me know that i’ve been around for a while developing software and am pretty conservative when it comes to hype and the next big thing… I remember how XML was going to change the world… but i’d been around long enough to remember (and work with) SGML…. invented in the mid 70s, of which XML is derived from (this is Bill writing not Stu - Stu’s a little more excitable!)

Anyway, after OzDevCon06 I came back and purchased Profiler. In the past with big system I’ve manually written code to profile and benchmark bottlenecks, or expected bottlenecks!

To cut to the chase, it is possible using the debugger to get a feel for the event driven nature of your program flow. But it is still difficult to be certain when events are firing and what processes are being called. Especially OCX callbacks and other time critical routines.

My current project is a large system with some very complex screens (I’ve gone to a lot of trouble to make the screens easy and concise for the users… which often seems to have the inverse effect on the code). One screen took upwards of 4 seconds to finish its housework one close. Now, before you all laugh at me, the product is in beta and I knew it needed tuning. My instinct told me database was the most likely issue and many tables are updated on pressing [Ok].

But with Profiler and the techniques Bruce demonstrated, I had loaded this project, found over 3.5 seconds of the problem, fixed it and recompiled within 10 minutes.

For the sake of completeness and so my friends can tease me, i’ll briefly explain what i was doing wrong.

In all my systems, for each update window, all field level validation including hiding and unhiding of controls is centralised in one rountine RefreshFields. Any field that requires validation just calls RefreshFields after the Accept event and its all handled in one place. Usually this is very rudimentry code, and centralising ensure i can easily prepare a window after open with just one call to RefreshFields and all controls are handled correctly without concern. But… as is always the case when you realise you’ve screwed up, this one was a little more complex. Profiler told me it was taking between 150 and 400 ms to execute… but the real shocker was…. 17 times… just when i click close! It is at this point that we all realised it was being called for every control with the RefreshFields as part of the normal AcceptAll validation process… now this lazyness in my coding (I have a life-time membership to the lazy programmers club) never really causes a problem… except except except…

So of course I just added a switch so this code executes once on AcceptAll and problem solved… This good habit will now be adopted, forthwidth!

So a big thanks to Bruce and the Team at Capesoft for an exceptional tool. 10/10!

3 Comments »

  1. I witnessed this event - I can confirm it was impressive stuff, in about 1.5 minutes development time the screen in question was tuned about 500% !

    Stu - Bill also is hated by WordPress, it tried to eat his post too. Gots to default that GUI option off for all users.


    CodeMonkey

    Comment by Adam — May 5, 2006 @ 12:29 am

  2. I ran Profiler on a project while at the conference. I had a rather busy routine that had to make a LOT of decisions. I just knew there would be time intensive code there. Profiler showed this not to be the case and what I wrote was actually damn fast!

    I showed one interesting odd behavior to Bruce with the RUN command and Bruce was going to look into it, but RUN is an odd case.

    But Profiler has a nice hidden use in that you can validate that nothing more can be gained by tweaking code. I consider Profiler a mandatory tool in your debugging tool kit.

    BTW - I have some other areas I need to profile. ;-)

    Comment by Russ Eggen — May 5, 2006 @ 1:11 am

  3. How cool is this tool (Profiler, not me :)).

    And yeah, I definately see the cracks in Wordpress, I’m mulling over the whole editor thingy. There will be others who have had the same problem.

    Comment by Stu — May 5, 2006 @ 7:24 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress