Sunday, April 10, 2005

Heuristics for optimization

Where to look (in what order):
  1. Data transfer layers (Business Logic -> GUI), (Database->BusinessLogic). Often you're pulling too much or too little back.
  2. Unoptimized algorithms. Often you have O(n^3) algorithms based on naive implementations. These are easy to pull apart.
  3. Database retreival. Look for low hanging fruit like full table scans.
What to do (in what order):
  1. Play with the granularity of what you return. When you transfer large things you usually need less information per item. When you return a few things you usually need more information per item. Your code will need to handle this diversity.
  2. Play with how you've done calculations, and composed your data.
  3. Add indexes to your database, use a DB specialist to help with your queries.

What tools you need:

  1. A profiler gives you macro views of where your code is running. I have found no other way to get this information. They give you a place where hunches and hypotheses start. However they tend to stop being useful after that - you are still to distant from the code.
  2. Println. I use it heavily. Actually I wrap it in a Profiler class, but generally it tells me that between these two lines of code it took x milliseconds. Using binary search you can track down where the code is slow.

0 Comments:

Post a Comment

<< Home