Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Java JIT optimization friendly code?

Tags:

java

real-time

When you want to squeeze the last bit of performance from your code, you would want to utilize the JIT optimization as best as you can. For example, marking method final for easy method inlining , avoid polymorphism in critical places, etc.

But I couldn't find any reference or list of options that a java programmer can use to 'hint' the JIT compiler for faster code? Shouldn't we have a list of 'best programming' practice for low latency performance from JIT ?

like image 253
Sajid Avatar asked Jun 30 '11 23:06

Sajid


1 Answers

The best way to write JIT-friendly code is to write straight, simple code because this is what the JIT looks for and knows how to optimize. No tricks!

Also different JVM's have different JIT's, so in order to be certain your code works well with all of them you must not rely on any of them.

The usual way to improve JIT-performance is through external configuration of the JVM. As most JVM's these days know how to inline code small method calls directly, most performance gains come from configuring the garbage collector. Here much effort is used in avoiding having to stop your program while collecting, and you can tweak quite a bit with your knowledge of how the underlying hardware is configured and what works better than others. But not the Java code, it needs to be straight and simple.

like image 200
Thorbjørn Ravn Andersen Avatar answered Sep 23 '22 18:09

Thorbjørn Ravn Andersen