[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-core-libs-dev
Subject:    Re: RFR: 8301552: Use AtomicReferenceArray for caching instead of CHM in ZoneOffset
From:       Per Minborg <pminborg () openjdk ! org>
Date:       2023-01-31 16:09:36
Message-ID: 1su0_EK4Sx_blL9MQLS7147NWLaYH80QCSvM2iyV7h4=.6c053033-45ce-4234-912c-3de05ee0ef46 () github ! com
[Download RAW message or body]

On Tue, 31 Jan 2023 15:57:43 GMT, Per Minborg <pminborg@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 432:

> 430:         if (totalSeconds % (15 * SECONDS_PER_MINUTE) == 0) {
> 431:             int slot = cacheSlot(totalSeconds);
> 432:             ZoneOffset cached = SECONDS_CACHE.get(slot);

I miss `AtomicReferenceArray::computeIfNull` that atomically will compute an element \
if the value at a certain index is `null`.

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

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic