Yes, it's 2 subclasses hierarchy.
https://github.com/iselo/jdk-optional/tree/master/lib/src
I'm open to learning about my pitfalls.
# JMH version: 1.36
# VM version: JDK 20.0.2, Java HotSpot(TM) 64-Bit Server VM, 20.0.2+9-78
# VM invoker:
/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Hom
Can you share the benchmark code? Maybe C2 profiled class hierarchy,
determined your optional only has 2 subclasses and can thus generate
optimized machine code. Or maybe your benchmark is wrong that the result is
not consumed by blackhole so the whole benchmark is moot. We need the code
to make a
Now it is clear. Sorry for the inconvenience. Thank you for your time. I
appreciate.
On Mon, 28 Aug 2023 at 2:03 PM Quân Anh Mai wrote:
> Tbh I have a hard time understand what you are trying to convey. Please
> write grammatically correct sentences with clear structure.
>
> I notice you attach
Tbh I have a hard time understand what you are trying to convey. Please
write grammatically correct sentences with clear structure.
I notice you attach benchmark results but I don't see what was benchmarked
to produce those results.
Another point is that Value classes has not been delivered yet,
Thank you Quân.
All you saying guys make sense.
Yes there is a difference calling methods by pointer and involving vtable.
But one thing didn't came out of my head:
If virtual dispatch dispatch is 10-time more expensive and polymorphism is
a performance killer so how combinations of "return optio
Hi,
Polymorphism is a performance killer. Normally this does not matter much,
but for thin wrappers such as Optional, this is one of the most important
factor.
Behaviour polymorphism requires virtual dispatch and prevents inlining.
This is really detrimental, as simple operations such as a getter
Thanks Roger, Remi.
Just want to understand full picture.
For both solutions, private static final nested class and dynamic anonymous
overloading, based on dipole/boolean pattern where all methods has opposite
charge, JVM produces separate code for classes that in total has:
- >10% less commands,
Hi,
Also, Null checks in the VM are very cheap, likely cheaper than a
virtual dispatch.
Adding calls to requireNonNull is almost always a no-op, except for
adding a variable name to the exception it still throws NPE. A
frequently used class like Optional will be compiled to machine code and
t
Sorry, you can not do that.
Optional is a value based class [1] (see the javadoc) so the class has to be
final.
And more generally, the API of a classes of OpenJDK will not change based on
some stylistic issue, OOP or not.
regards,
Rémi Forax
[1]
https://docs.oracle.com/en/java/javase/20