Friday, July 3, 2009

Performance Optimization in Java

  • Use byte instead of int for Percent
  • Declare constants in interfaces instead of declaring static final members in class
  • Use custom date class/long for Date/Calendar
  • Use string.intern() to cache strings
  • Use bitset instead of boolean arrays. use custom class for ObjectStatus
  • Implement parent, child relationship in objects
  • String comparison
string1 == string2 before comparing string1.length() == string2.length() && string1.equals(string2)
  • Use StringBuffer for string concatnation
  • reduce conversion between strings and numbers/ maintain a hashmap of strings to numbers for commonly used numbers lets say 1 to 100
  • use caching for web services - EhCache with configurable session timeout
  • use caching for transformed objects - EhCache with configurable session timeout
  • Session Serialization
  • do not keep clob's, blob's in serialized objects
  • use wrappers around such objects / implement inheritance to move clobs to derived classes
  • original values, which wont change during session - should be trimmed only to hold necessary information
  • use multiple session attributes for storing objects in session
  • create context object to pull values from session in a filter
  • and use the context object at later stages instead of session
  • at the end of response, in the filter update session attributes - depending on the dirty objects
  • use obfuscator, compiler options to reduce code size
  • http://www.j2ee.me/docs/books/performance/1st_edition/html/JPTOC.fm.html
  • http://www.swtech.com/java/optimize/
  • Timer - http://www.glenmccl.com/jperf/#Sample1
  • http://www.javaperformancetuning.com/tips/rawtips.shtml

No comments:

Post a Comment