java.util.Optional: a better implementation?
aleksey.shipilev at oracle.com
Wed Oct 29 12:43:01 UTC 2014
On 29.10.2014 15:25, David Holmes wrote:
> On 29/10/2014 10:06 PM, nicarran at gmail.com wrote:
>> The JVM probably optimizes and throws away the null checks yielding in
>> equal performance compared to the proposed implementation (above) ---I
>> haven't done any performance tests----, but why wait for the JVM when
>> this implementation is also nicer to read? What do you think?
I think most of the null checks will be folded into implicit null
checks, which will have null (pun intended) effect on performance. What
you suggest, however, will probably explode otherwise monomorphic calls
to Optional to bimorphic calls to Optional.Empty/Optional.present -- and
that will affect performance.
You can make a few benchmarks to quantify those effects -- out of
curiosity. I don't think the minute improvements, if any, will justify
exploding the class hierarchy though.
More information about the core-libs-dev