On Wed, 1 Feb 2023 13:18:31 GMT, Per Minborg <pminb...@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. > > Per Minborg has updated the pull request incrementally with two additional > commits since the last revision: > > - Simplify benchmark > - Add benchmark A > 3X performance increase is obtained via this PR for `ZoneOffset::ofTotalSeconds` for values from the cache (higher is better): Baseline Result "org.openjdk.bench.java.time.ZoneOffsetBench.getFromCache": 1.088 ±(99.9%) 0.019 ops/us [Average] (min, avg, max) = (1.046, 1.088, 1.109), stdev = 0.018 CI (99.9%): [1.069, 1.108] (assumes normal distribution) PR Result "org.openjdk.bench.java.time.ZoneOffsetBench.getFromCache": 3.710 ±(99.9%) 0.031 ops/us [Average] (min, avg, max) = (3.651, 3.710, 3.745), stdev = 0.029 CI (99.9%): [3.680, 3.741] (assumes normal distribution)  ------------- PR: https://git.openjdk.org/jdk/pull/12346