This post is about performance factors in java. There are many performance factors in java. Here i am mentioning some of the performance factors which i have used in early days in java. I will keep posted some approach, experience on performance improvement. some of the performance tips are,
- ArrayList is faster than Vector except when there is no lock acquisition required.
- Use StringBuffer in place of String if you are doing lots of string manipulation it will reduce memory by avoiding creating lots of string garbage. If you are using java5 then consider StringBuilder but that is not synchronized so beware.
- Try to make variable , class , method final whenever possible that’s allow compiler to do lots of optimization e.g. compile time binding so you will get faster output.
- Static methods are bonded compile time while non static methods are resolved at runtime based on object type so static method will be faster than non static.
- Don't call methods in for loop for checking condition e.g. length() size() etc. instead of doing this , use modified version.
- Use exceptions only where you really need them
- Local variables are the faster than instance variables, which are in turn faster than array elements
- Use the fastest available JVM
- '==' is faster than equals()
- Creating Doubles from strings is slow
- Combine similar loops
- Don't create too may objects
- Beware of object leaks (references to objects that are never nulled)
- Use Lazy loading to avoid unnecessary pre-loading of child data
- Do bulk updates to reduce database calls
- Use the print() method rather than the println() method
No comments:
Post a Comment