<i18n dev> RFR: 8345668: ZoneOffset.ofTotalSeconds performance regression [v3]
Shaojin Wen
swen at openjdk.org
Sat Dec 21 00:02:35 UTC 2024
On Fri, 20 Dec 2024 23:46:57 GMT, Naoto Sato <naoto at openjdk.org> wrote:
>> For example:
>>
>> static final AtomicReferenceArray<ZoneOffset> MINUTES_15_CACHE = new AtomicReferenceArray<>(37 * 4);
>>
>> public static ZoneOffset ofTotalSeconds(int totalSeconds) {
>> // ...
>> int minutes15Rem = totalSeconds / (15 * SECONDS_PER_MINUTE);
>> if (totalSeconds - minutes15Rem * 15 * SECONDS_PER_MINUTE == 0) {
>> int cacheIndex = minutes15Rem + 18 * 4;
>> ZoneOffset result = MINUTES_15_CACHE.get(cacheIndex);
>> if (result == null) {
>> result = new ZoneOffset(totalSeconds);
>> if (!MINUTES_15_CACHE.compareAndSet(cacheIndex, null, result)) {
>> result = MINUTES_15_CACHE.get(minutes15Rem);
>> }
>> }
>> return result;
>> }
>> // ...
>> }
>
> Hi Shaojin,
> Thanks for the suggestion, but I am not planning to improve the code more than backing out the offending fix at this time. (btw, cache size would be 149 as 18:00 and -18:00 are inclusive)
Can I submit a PR to make this improvement?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22854#discussion_r1894509276
More information about the i18n-dev
mailing list