On Fri, 20 Dec 2024 21:06:16 GMT, Naoto Sato <na...@openjdk.org> wrote:

>> The change made in 
>> [JDK-8288723](https://bugs.openjdk.org/browse/JDK-8288723) seems innocuous, 
>> but it caused this performance regression. Partially reverting the change 
>> (ones that involve `computeIfAbsent()`) to the original. Provided a 
>> benchmark that iterates the call to `ZoneOffset.ofTotalSeconds(0)` 1,000 
>> times, which improves the operation time from 3,946ns to 2,241ns.
>
> Naoto Sato has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Fixed compile error

src/java.base/share/classes/java/time/format/DateTimeTextProvider.java line 316:

> 314:             store = createStore(field, locale);
> 315:             CACHE.putIfAbsent(key, store);
> 316:             store = CACHE.get(key);

should this be 
`store = CACHE.computeIfAbsent(key, e -> createStore(e.getKey(), 
e.getValue()));`

That still allow the optimistic/concurrent get call to succeed most of the time 
(when already cached) but reduce the interactions with the map when a value is 
created/set/accessed the first time.

Alternatively, the result of `putIfAbsent` could be checked/used to avoid the 
second call to `get`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22854#discussion_r1898012555

Reply via email to