Java Performance Hints

This document contains some hints how to ensure good performance (memory-wise and execution speed) in Java code. The hints are sometimes intentionally kept quite short without examples so that the reader will have to study the subject (and understand it) before implementing the hint. Some hints may be of theoretical usefulness only and saves nanoseconds at best, other are crucial for good performance. Most are generally applicable, some are only valid for Java 5 or Java 6. Java 7 is not yet covered.

top

Strings

top

Collections

top

Arrays

top

Garbage Collection

top

GUIs and Swing

top

Threads

top

Files

top

Classes (and their fields and methods)

top

Objects in general

top

Miscellaneous

top

Articles and Books

top

Performance related sites

Footnotes

Escape analysis and lock elision: As first described in JavaOne session TS-3412 2006 (but it states the wrong flag, UseEscapeAnalysis) and now documented in Java HotSpot Virtual Machine Performance Enhancements, escape analysis is available and enabled by default. Old JDK versions use the -XX:+DoEscapeAnalysis flag ("not stable"). It is for the server compiler only.