David Murdoch
David Murdoch

Reputation: 89322

Most hazardous performance bottleneck misconceptions

The guys who wrote Bespin (cloud-based canvas-based code editor [and more]) recently spoke about how they re-factored and optimize a portion of the Bespin code because of a misconception that JavaScript was slow. It turned out that when all was said and done, their optimization produced no significant improvements.

I'm sure many of us go out of our way to write "optimized" code based on misconceptions similar to that of the Bespin team.

What are some common performance bottleneck misconceptions developers commonly subscribe to?

Upvotes: 9

Views: 957

Answers (8)

alex
alex

Reputation: 5201

  • Relational databases are slow.
  • I'm smarter than the optimizer.
  • This should be optimized.
  • Java is slow

And, unrelated:

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

-jwz

Upvotes: 6

Dave Sherohman
Dave Sherohman

Reputation: 46187

"This has to be as fast as possible."

If you don't have a performance problem, you don't need to worry about optimizing performance (beyond just paying attention to using good algorithms).

This misconception also manifests in attempts to optimize performance for every single aspect of your program. I see this most often with people trying to shave every last millisecond off of a low-volume web application's execution time while failing to take into account that network latency will take orders of magnitude longer than their code's execution time, making any reduction in execution time irrelevant anyhow.

Upvotes: 5

Donal Fellows
Donal Fellows

Reputation: 137567

The rules are simple:

  1. Try to use standard library functions first.
  2. Try to use brute-force and ignorance second.
  3. Prove you've got a problem before trying to do any optimization.

Upvotes: 2

Mike Dunlavey
Mike Dunlavey

Reputation: 40669

In no particular order:

"Ready, Fire, Aim" - thinking you know what needs to be optimized without proving it (i.e. guessing) and then acting on that, and since it doesn't help much, therefore assuming the code must have been optimal to begin with.

"Penny Wise, Pound Foolish" - thinking that optimization is all about compiler optimization, fussing about ++i vs. i++ while mountains of time are being spent needlessly in overblown designs, especially of data structures and databases.

"Swat Flies With a Bazooka" - being so enamored of the fanciest ideas heard in classrooms that they are just used for everything, regardless of scale.

"Fuzzy Thinking about Performance" - throwing around terms like "hotspot" and "bottleneck" and "profiler" and "measure" as if these things were well understood and / or relevant. (I bet I get clobbered for that!) OK, one at a time:

  • hotspot - What's the definition? I have one: it is a region of physical addresses where the PC register is found a significant fraction of time. It is the kind of thing PC samplers are good at finding. Many performance problems exhibit hotspots, but only in the simplest programs is the problem in the same place as the hotspot is.

  • bottleneck - A catch-all term used for performance problems, it implies a limited channel constraining how fast work can be accomplished. The unstated assumption is that the work is necessary. In my decades of performance tuning, I have in fact found a few problems like that - very few. Nearly all are of a very different nature. Rather than taking the shortest route from point A to B, little detours are taken, in the form of function calls which take little code, but not little time. Then those detours take further nested detours, sometimes 30 levels deep. The more the detours are nested, the more likely it is that some of them are less than necessary - wasteful, in fact - and it nearly always arises from galloping generality - unquestioning over-indulgence in "abstraction".

  • profiler - a universal good thing, right? All you gotta do is get a profiler and do some profiling, right? Ever think about how easy it is to fool a profiler into telling you a lot of nothing, when your goal is to find out what you need to fix to get better performance? Somewhere in your call tree, tuck a little file I/O, or a little call to some system routine, or have your evil twin do it without your knowledge. At some point, that will be your problem, and most profilers will miss it completely because the only inefficiency they contemplate is algorithmic inefficiency. Or, not all your routines will be little, and they may not call another routine in a small number of places, so your call graph says there's a link between the two routines, but which call? Or suppose you can figure out that some big percent of time is spent in a path A calls B calls C. You can look at that and think there's not much you can do about it, when if you could also look at the data being passed in those calls, you could see if it's necesssary. Here's a fun project - pick your favorite profiler, and then see how many ways you could fool it. That is, find ways to make the program take longer without the profiler being able to tell what you did, because if you can do it intentionally, you can also do it without intending to.

  • measure - (i.e. measure time) that's what profilers have done for decades, and they take pride in the accuracy and precision with which they measure. But measure what time? and why with accuracy? Remember, the goal is to precisely locate performance problems, such that you could fruitfully optimize them to gain a speedup. When you get that speedup, it is what it is, regardless of how precisely you estimated it beforehand. If that precision of measurement is bought at the expense of precision of location, then you've just bought apples when what you needed was oranges.

Here's a list of myths about performance.

Upvotes: 18

slacker
slacker

Reputation: 2142

  • Optimizing the WRONG part of the code (people, use your profiler!).
  • The optimizer in my compiler is smart, so I don't have to help it.
  • Java is fast (LOL)
  • Relational databases are fast (ROTFL LOL LMAO)

Upvotes: 5

BillThor
BillThor

Reputation: 7576

My rules of optimization.

  • Don't optimize
  • Don't optimize now.
  • Profile to identify the problem.
  • Optimize the component that is taking at least 80% of the time.
  • Find an optimization that is 10 times faster.

My best optimization has been reducing a report from 3 days to 9 minutes. The optimized code was sped up from three days to three minutes.

In my carreer I have met three people who had been tasked with producing a faster sort on VAX than the native sort. They invariably had been able to produce sorts that took only three times longer.

Upvotes: 3

DancesWithBamboo
DancesWithBamboo

Reputation: 4156

If I convert the whole code base over to [Insert xxx latest technology here], it'll be much faster.

Upvotes: 6

Michael Dorgan
Michael Dorgan

Reputation: 12515

And this is what happens when one optimizes without a valid profile in hand. All you are doing without a profile is guessing and probably wasting time and money. I could list a bunch of other misconceptions, but many come down to the fact that if the code in question isn't a top resource consumer, it is probably fine as is. Kinda like unrolling a for loop that is doing disk I/O...

Upvotes: 14

Related Questions