Speaker: John Rose
See the table of contents
Deck: https://cr.openjdk.org/~jrose/pres/2026-0319-SpecializedGeneric.pdf
(encouraged to follow along on own device because goes fast/info dense)
C++ vs Java
- Both C++ templates and Java generics write well tuned ocde handling mainy times and give good performance (on a good day)
- Java’s are dynamic where C++ specialized code for each case at complier time. Java generic can operate on types unknown at compile time.
Performance
- Java hand tuned code equivalent to C++ templates
- For some reason reflection is faster in some cases
- Was fast due to profiling, de-virtualized (knowing type), inlining code.
Boxing
- Overhead – pointer -> Header + payload
- primitives don’t mix well with generics yet
- Valhalla will make any value class flattenable reducing array access costs
- Flatter is faster and arrays typically stick to one type
Monomorphic
- Only one type/form
- Native machine code
- Looks static even though written dynamically for the JVM
- Even if became monmorphic after running a long time
Bimorphic profiles
- JVM struggles to optimize two types at the same time
Megamorphic
- Falls apart when three types
- Real code could have lots of types
- Performance cliff
- More dynamic stuff requires more static stuff
- Megamorphic code is two to five times slower than monomorphic code
Open questions
- How far can go transparently?
- Do we need new language features to improve performance?
Experiment – Hidden class
- Clone a class file into a hidden class and call the cloned methods.
- A hidden class isn’t in any specific namespace.
- Can be docked into a namespace and call private methods
Future
- Parametric JVM with Valhalla
Note
- C.A.R (Tony) Hoare was the inventor of QuickSort. He passed away this month.
My take
Glad he shared the slides. It’s helpful to be able to scroll and compare some of the performance numbers. Also some slides had a lot so easier to read right in front of me. This was very interesting. I enjoyed the deep dive. The numbers were interesting and the bytecode was interesting. I do wish this was earlier in the day as my brain is pretty full and there’s a lot of info here. The soup analogy was fun and helpful!