Wednesday, July 04, 2012

Tip of the Day: Performance Code Review


Here are some general best practices to consider around performance code review.

These tips are by no means definitive, but serve as reminders to developers what they should consider in a checklist.

Note: performance code reviews are really not separate processes from a general code review.
  • Objects are duplicated only when necessary. If you must duplicate objects, consider implementing Clone and decide if deep cloning is necessary.
  • No busy-wait loops instead of proper thread synchronization methods. For example, avoid while(true){ ... sleep(10);...}
  • Avoid large objects in memory, or using String to hold large documents which should be handled with better tools. For example, don't read a large XML document into a String, or DOM.
  • Do not leave debugging code in production code.
  • Avoid System.out.println(); statements in code, or wrap them in a boolean condition statement like if(DEBUG) {...}
  • "Optimization that makes code harder to read should only be implemented if a profiler or other tool has indicated that the routine stands to gain from optimization. These kinds of optimizations should be well documented and code that performs the same task should be preserved." - UNKNOWN.

    Note: I found this gem a few years ago, but it is so true. If anyone knows who said this, please comment.


Popular Posts