Get Mystery Box with random crypto!

Overhead of Returning Optional Values #corelibs #performance O | Java Tech News

Overhead of Returning Optional Values
#corelibs #performance
Optional class stores a value that might be absent. Every language adapts to null-safety as it the best practice. However, Java language imposes some performance tradeoffs of using Optional feature. As long as you don't write an extreme runtime performance program you shouldn't care much about it. But if we care about performance? How much do optionals actually cost?

Scalar replacement, inlining and escape analysis of JIT compilator have to perform proper optimizations on a simple benchmark as in the article. However, disassembly output of the benchmark with Optional shows that:
• Escape analysis failed to provide JIT good options for applying scalar replacement. However, the inlining of hot methods has been made.
• No SSE/AVX used anywhere. Sample hasn’t been vectorized, despite being an ideal case for vectorization.
• Performance degradation can be up to x8 worse than using plain scalar values.
pkolaczk.github.io/overhead-of-optional/