RFR: 8359936: StableValues can release the underlying function after complete computation [v3]

Per Minborg pminborg at openjdk.org
Thu Jun 19 12:52:30 UTC 2025


On Thu, 19 Jun 2025 11:01:28 GMT, ExE Boss <duke at openjdk.org> wrote:

>> Per Minborg has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:
>> 
>>  - Merge branch 'master' into sv-release-supplier2
>>  - Fix performance regression
>>  - Clean up
>>  - Fix bug
>>  - Simplify
>>  - Revert to records
>>  - Make code more like the old one
>>  - Add removable underlying functions
>
> src/java.base/share/classes/jdk/internal/lang/stable/StableSupplier.java line 46:
> 
>> 44:     @Override
>> 45:     public T get() {
>> 46:         return delegate.orElseSet(underlyingHolder.underlying(), underlyingHolder);
> 
> By avoiding reading from `underlyingHolder` when the `StableValue` is already set, this can avoid the overhead of a field read from `underlyingHolder`:
> Suggestion:
> 
>         final Object t = delegate.wrappedContentsAcquire();
>         if (t != null) {
>             return unwrap(t);
>         }
>         return delegate.orElseSet(underlyingHolder.underlying(), underlyingHolder);

Before this proposal:


Benchmark                               Mode  Cnt  Score   Error  Units
StableSupplierBenchmark.stable          avgt   10  1.369 ± 0.019  ns/op
StableSupplierBenchmark.staticStable    avgt   10  0.343 ± 0.005  ns/op
StableSupplierBenchmark.staticSupplier  avgt   10  0.389 ± 0.008  ns/op
StableSupplierBenchmark.supplier        avgt   10  1.739 ± 0.047  ns/op


After this proposal:


Benchmark                               Mode  Cnt  Score   Error  Units
StableSupplierBenchmark.stable          avgt   10  1.436 ± 0.120  ns/op
StableSupplierBenchmark.staticStable    avgt   10  0.352 ± 0.044  ns/op
StableSupplierBenchmark.staticSupplier  avgt   10  0.346 ± 0.016  ns/op
StableSupplierBenchmark.supplier        avgt   10  1.588 ± 0.035  ns/op. <-- !


So, it appears to be some gain here.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25878#discussion_r2156934164


More information about the core-libs-dev mailing list