开发者

How to write Java JIT optimization friendly code?

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, et开发者_如何学运维c.

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 ?


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.


The HotSpot authors and others have repeatedly stated that the best approach is to write simple straightforward code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜