<i18n dev> RFR: 8301552: Use AtomicReferenceArray for caching instead of CHM in ZoneOffset

Andrey Turbanov aturbanov at openjdk.org
Wed Feb 1 08:00:51 UTC 2023


On Tue, 31 Jan 2023 15:57:43 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> `ZoneOffset` instances are cached by the `ZoneOffset` class itself for values in the range [-18h, 18h] for each second that is on an even quarter of an hour (i.e. at most 2*18*4+1 = 145 values). 
> 
> Instead of using a `ConcurrentHashMap` for caching instanced, we could instead use an `AtomicReferenceArray` with direct slot value access for said even seconds. This will improve performance and reduce the number of object even though the backing array will go from an initial 32 in the CHM to an initial/final 145 in the ARA. The CHM will contain much more objects and array slots for typical numbers of entries in the cache and will compute hash/bucket/collision on the hot code path for each cache access.

src/java.base/share/classes/java/time/ZoneOffset.java line 147:

> 145: 
> 146:     /** Cache of time-zone offset by offset in seconds [-18h, +18h] for each even quarter of an hour. */
> 147:     private static final AtomicReferenceArray<ZoneOffset> SECONDS_CACHE = new AtomicReferenceArray<>(MAX_SECONDS_CACHE_SLOT * 2 + 1);

Can we use regular array instead?

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

PR: https://git.openjdk.org/jdk/pull/12346


More information about the i18n-dev mailing list