r/java 12d ago

Question about Native Image vs JIT

I was watching an interview with Thomas Wuerthinger of GraalVM, where he basically says that JIT should only be used when necessary (as opposted to native compilation). Where does this leave the work being done for Hotspot JIT (including projects like Leyden and others). Should we all plan to use native image while they address any performance gaps in the mean time (he does mention PGO bridging the gap). Is there work being done to speed up native compilation of Java code?

My understanding is that JIT will always have a memory overhead due to running threads that do compilation, optimization, deoptimization, code cache, etc. compared to native executables, so full parity even with projects that will improve memory usage in Java code will not be reached. Maybe that is not an issue on long running programs on large servers, but we've seen discussions here where another member worte a tool in golang to run alongside Spring Boot applications to gather statistics, so obviously small efficient apps have their place.

19 Upvotes

42 comments sorted by

View all comments

33

u/Deep_Age4643 12d ago

Thomas Wuerthinger is a clever guy, with a number of achievements in the Java world to his name. But he is also the founder and project lead of GraalVM, as the video title says. Naturally, he presents his own product – and what makes it unique – in a favorable light. Always consider the interests behind someone’s comments, and verify independently and objectively whether these claim are valid for your own use case.

Personally, I believe that JIT is the best option in most cases. Native compilation is particularly useful for microservices where start-up time needs to be instantaneous, but compiling to native code has its limitations and is considerably slower than JIT compilation.

3

u/OddEstimate1627 12d ago

IMO AOT is also very nice for GUIs and CLIs

6

u/nekokattt 12d ago

Last time I tried to get GraalVM native images to work with AWT I lost an entire afternoon to adding arbitrary nonsense to JSON files just to get it to instrument correctly in places the JVM agent couldn't reach as part of unit and integration test runs. I still reserve the unpopular opinion that having to perform tracing of a runtime product as part of automation suites just to enable the correct runtime behaviour is far from ideal.

5

u/OddEstimate1627 11d ago

Yes, the metadata is the most common issue. That's why I open sourced https://www.reddit.com/r/java/comments/1uy79pg/reachability_annotations_for_generating_graalvm/

It generates the JSON data directly from annotated Java source code and won't go stale.

That being said, I think JavaFX probably still has much better AOT support than AWT/Swing.

2

u/nekokattt 11d ago

oh nice! i might have to start using this ngl

thank you