Performance Tuning

In my previous article on Performance Requirements I argued that performance issues are requirements, and that this is not well understood in the software development community in general. In this article I’m going look at the performance tuning of existing code, argue that this is also poorly understood, and discuss the right way to go about it.

My friend Alan Griffiths related an experience of his from a few years ago. He was working on a desktop product written in C++. In this case the performance requirements of the software had been managed sensibly, in that performance criteria were understood. Alan was tasked with improving the performance of specific functionality by a factor of two.

How to go about this? Well, the functionality he was tasked with optimising used did quite a lot of searching and sorting of data. This had led to an implicit assumption (among some members of the development group) that this is where the improvements would be needed. However, the C++ development environment in use had a profiler, so Alan set about obtaining concrete information on where the problem really was – and the result was something of a surprise! Execution seemed to be spending a lot of time in string::operator== ! A quick look in the library source code quickly gave a clue: the operator== implementation simply called the C strcmp function. Alan decided that he had, at this point, obtained enough information to try something simple: he wrote a replacement operator== that first checked if the strings were of equal length, and simply returned false if they were not. This was enough to solve the problem! In fact, it delivered a factor of four improvement – twice as much as was deemed necessary – at no extra charge!

I have, many times throughout my career, seen programmers dive in and start speeding up code based on guesswork and unfounded assumptions – indeed, in my less experienced days I dare say I was guilty of this myself (just don’t tell anyone). This is a waste of time. Alan could easily have spent lots of time trying to optimise searching and sorting code, when this time would have been wasted. Unless you actually measure the performance of various parts of the code, you don’t know what is causing the code to under-perform. As illustrated above, this is true even if there are “obvious” candidates!

The moral of this story is a recurring theme: avoid guessing! Instead, gather concrete evidence of where the problem lies before making changes to the code.

4 Comments

  1. John:

    Pedantic perhaps but you’re really looking to identify a bottleneck / which bit of code is used most (and is therefore worth optimising) rather than a “problem”. After all there’s no point optimising code that doesn’t actually work correctly.

  2. MarkR:

    I think to be honest it’s semantics rather than pedantic (sorry). I would argue that if software is not meeting its performance criteria then there is a problem to be solved. However I agree with you re there being no point optimising code that isn’t working (in the functional sense), and I think this is a point I have so far made by implication, but failed to make explicit.

    Thanks for this John, as I think you’ve just handed me an idea for another article :-)

  3. John:

    I’ll stick the bill in the post ;-)

  4. Alan:

    I think you’ve misremembered the story. The scenarios I was optimising were running much more that 2 times too slow (i.e. 10+ times slower than the existing product). This was following the replacement of a dummy persistence layer (used during development) with a persistance layer that moved inactive objects out to a database.

    The “obvious” place to look was the queries and indexes in the database or faulty logic that decided when to save or recover objects.

    As you relate, however, the problem proved to be something else entirely. Which is the main point of the story.

Leave a comment

?>ungloryhole.com ungloryhole college rules rubs a huge cock collegerules Aiden Aspen Special Exercises tugjobs camel toe publicinvasion shaved pussy hammered collegerules pussy pounded VINTAGEGAYLOOPS smacked those asses trannyland Gia Malone Stephanie Cane bait Bus GynoOrgasmVideos Milf cravers publicinvasion submit your bitch public invasion Nude sport videos itsgonnahurt its gonna hurt Bareblacking tug jobs haze him outinpublic collegerules.com Kat drills submityourbitch Confession Of Married Man Latina pornstar pussy SpecialExercises fat mature redhead sexy blonde petite Aiden Aspen Vince Ferelli CODYCUMMINGS Alexis Fawx NEXTDOORPASS Sexy big tits pornstar itsgonnahurt itsgonnahurt outinpublic Licking Dick And Ass fat asses publicinvasion NEXTDOORPASS dildo drills her pussy busty adventures collegerules.com pussy covered hazehim bang pas facialfest porn star fucked hard pussy licked NEXTDOORBUDDIES lesbian dildo drilling publicnude outinpublic.com ungloryhole VISCONTITRIPLETS lucky stud in a hot threesome Ice La Fox tugjobs Brooke Banner Blonde round ass hazehim.com public invasion ungloryhole public invasion fat juicy ass. Big Mouthfuls Angelina Valentine submityourbitch Lacey lounging tranny land lesbian lover licks public invasion fucking ass and pussy haze him milf lessons Roxy Love TOMMYDXXX out in public public invasion publicinvasion public invasion tight ass drilled Lesbian sport videos facial fest assparade amazing blowjob Big tit fucked NEXTDOORHOOKUPS outinpublic submityourbitch milfsoup publicinvasion public invasion collegerules outinpublic.com Summer Bailey collegerules.com GAy Cumshots Extrem college rules Lesbiansportvideos submit your bitch fuck team five milfsoup natural beautiful tits magical feet BIGGEST ASS CRAVING Nudesportvideos bangbus submityourbitch summer time milf MedicalFemdom tranny land outinpublic.com Special Examination Medical Femdom Amy Reid submityourbitch.com outinpublic NEXTDOORMALE evanrivers outinpublic Monsters Of Cock MALEDIGITAL publicinvasion Gyno Orgasm Videos Bang Bros SpecialExamination haze him collegerules.com hazehim hottest white girls tranny land firm tits publicinvasion itsgonnahurt un glory hole CIndia Summers publicinvasion Redhead BBW 3DS Max 8 OEM3Q 3GP Video Converterdownload acdsee manager 2009 oemred eye remover pro 1.2cheapest windows vistacheapest windows vista ultimatecheap AutoCAD 2009Vision Backup Enterprisecheap Macromedia ColdFusionnero photoshow 5 downloadadobe photoshop cs oemcoldfusion mx 7 downloadkamagra sildenafil citratekamagra generic viagraorder caverta onlinecaverta 100buy cavertatadaliscasodex 50 mg tablet