Benchmarking the cost of Java's EnumSet - A Second Look
Posted by nihathrael@reddit | programming | View on Reddit | 9 comments
Posted by nihathrael@reddit | programming | View on Reddit | 9 comments
davidalayachew@reddit
Pretty good article, and the JMH Benchmarks looked good from what I can see.
All I'll say is that, the JVM is a rapidly moving target, so numbers for September might be different for October, and even more different by November. Java the language innovates very carefully and deliberately. Slowly even, in the eyes of some other languages. But that is not true for the JVM.
For example, Java just released an Early Access Build of Value Classes a few weeks ago. Once Value Classes support Enums, the memory side of this benchmark is going to have to be completely redone lol.
Determinant@reddit
No, Valhalla won't provide any benefits for Enums because they aren't candidates for value classes. That's because the Java language specification guarantees that it's safe to rely on the object identity of enums.
nihathrael@reddit (OP)
Interesting, thanks for the clarification and explanation!
nihathrael@reddit (OP)
Thanks for pointing that out and linking to the Value Classes. That sounds pretty nice - looking forward to it hitting the full release. It'll be very interesting to see how much of difference it makes in the benchmark.
Determinant@reddit
Enums aren't candidates for Valhalla value classes so it won't affect the benchmarks
SirYwell@reddit
Regarding
Set.ofnot returning anEnumSet: For one, current EnumSet implementations are designed to be mutable, you'd need a new specialized implementation for immutability. But you'd also need to be able to detect that all values belong to the same enum in a way that doesn't slow down all the cases where you don't have enum values (or values from different enum types). Due to enum constants being able to have a custom body, this can be trickier than you might think :)nihathrael@reddit (OP)
Good point!
simon_o@reddit
Good effort.
I was completely baffled by the claims made in the first article, given no proper benchmarking setup was even attempted.
vytah@reddit
The main lesson here is you need to know how to write benchmarks, as it's too easy to write a benchmark that gets optimized away to nothing.