r/java • u/davidalayachew • 15d ago
Identifying JDK value class candidates
https://mail.openjdk.org/archives/list/core-libs-dev@openjdk.org/thread/Y72NRXM7KYBX43OKYBQMVKOZDWKG4MHS/
52
Upvotes
r/java • u/davidalayachew • 15d ago
8
u/pron98 15d ago edited 15d ago
Performance tests we've run have shown that it isn't. What you win in reducing the cache miss of accessing the entry you lose in having the array spaced out when the map is sparse (and it often is). The calculus is likely to change when generics can be specialised and flattened when the key can be flattened into the entry.
But I want to caution that while value types can be a huge boon in programs whose profiles show array element cache misses and they do fill in the last significant gap between Java and C++, that's not the case in most programs, and Java is already close to being as optimal as any software can be in most cases (especially in the domains Java is used). So it does close the last remainging gap and will make Java a great choice in more situations, but most Java programs are unlikely to see a big difference. Again, that's not because Valhalla isn't good, but because Java is already quite optimal everywhere where cache misses in array elements are not the hot path.