RFR: 8368825: Change the DateTimeFormatterBuilder::FIELD_MAP type from Map to Array [v2]

Naoto Sato naoto at openjdk.org
Tue Sep 30 16:36:22 UTC 2025


On Tue, 30 Sep 2025 03:25:28 GMT, Shaojin Wen <swen at openjdk.org> wrote:

>> The DateTimeFormatterBuilder::FIELD_MAP is of type Map<Character, TemporalField>, with key values in the range 'A-Z' and 'a-z'.
>> 
>> We can change the type of FIELD_MAP to an array of length 128 and then use char as an index to access the array.
>> 
>> This will reduce the memory usage of DateTimeFormatterBuilder::FIELD_MAP and improve performance slightly.
>> 
>> By analyzing the jmap dump memory, we can see that the memory size used by DateTimeFormatterBuilder::FIELD_MAP has dropped from 1.12kb to 528b, the number of objects has decreased and the memory has become more flat. as shown below:
>> * before
>> <img width="2018" height="1016" alt="image" src="https://github.com/user-attachments/assets/57d4c513-55c7-472e-95a8-9f7a4b47662d" />
>> 
>> * after
>> <img width="1894" height="352" alt="image" src="https://github.com/user-attachments/assets/89cbfb6c-360a-475f-85ea-4365d3b66871" />
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   use switch, from @RogerRiggs & @cl4es

src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java line 126:

> 124: import jdk.internal.util.DateTimeHelper;
> 125: import jdk.internal.util.DecimalDigits;
> 126: import jdk.internal.vm.annotation.Stable;

Leftover?

src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java line 2227:

> 2225:         // LDML - U - cycle year name, not supported by 310 yet
> 2226:         // LDML - l - deprecated
> 2227:         // LDML - j - not relevant

Do not remove these informational comments

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26634#discussion_r2392196321
PR Review Comment: https://git.openjdk.org/jdk/pull/26634#discussion_r2392210599


More information about the core-libs-dev mailing list