Heuristics for optimization
Where to look (in what order):
- Data transfer layers (Business Logic -> GUI), (Database->BusinessLogic). Often you're pulling too much or too little back.
- Unoptimized algorithms. Often you have O(n^3) algorithms based on naive implementations. These are easy to pull apart.
- Database retreival. Look for low hanging fruit like full table scans.
- 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.
- Play with how you've done calculations, and composed your data.
- Add indexes to your database, use a DB specialist to help with your queries.
What tools you need:
- 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.
- 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