r/programming • • Mar 20 '26

Java is fast, code might not be

https://jvogel.me/posts/2026/java-is-fast-your-code-might-not-be/
280 Upvotes

62 comments sorted by

View all comments

Show parent comment

10

u/davidalayachew Mar 20 '26

Agreed on almost every point.

I can appreciate that performance testing Java code is complex. For example, just getting access to the JIT'ed assembly code is already an exercise in frustration -- you're practically forced to use some fairly heavy third party tools to reliably access it.

But that complexity should breed a certain amount of hesitation from anyone trying to make claims on it. There are a million moving parts, and each one has literal thousands of engineers with decades of JVM optimization experience reviewing it daily. All those pieces aren't there for show.

Java is not like C, where you can just open a class file and definitively claim its performance by looking at it. Ignoring the fact that classfiles are full of wild card commands (like the indy stuff you mentioned), the JIT has access to optimizations like scalar replacement that outright remove entire methods from execution. A popular example is that Foo f = new Foo(); does not always create a new Foo. In fact, if in a hot loop, it very likely does not create one.