Java Performance

Premature optimization is the root of all evil

Donald Knuth

Rule 1:

  • Don't do it.

Michael A. Jackson. Principles of Program Design, Academic Press, 1975

We follow two rules in the matter of optimization:

Rule 2 (for experts only):

  • Don't do it yet

Measure!

Profiler

  • instrument all of the methods
  • methods "report" whenever they are run
  • bytecode of your classes is changed
  • crashed large apps

Sampler

  • lots of thread dumps
  • analyze stack traces
  • faster
  • does not require changes

Workshop

https://github.com/lingaro/java-performance-workshop

Compare!

Java
Microbenchmark

Harness

  • Hard to do reliably
  • Tiered Compilation: C1 - client, C2 server compiler
    • Level 0 –interpreted code
    • Level 1 – simple C1 compiled code (with no profiling)
    • Level 2 – limited C1 compiled code (with light profiling)
    • Level 3 – full C1 compiled code (with full profiling)
    • Level 4 – C2 compiled code (uses profile data from the previous steps)
  • Dynamic recompilation

Java Performance

By Krzysztof Rzymkowski