On Tue, 9 Dec 2025 10:02:36 GMT, Shaojin Wen <[email protected]> wrote:
>> This PR optimizes the parsing performance of DateTimeFormatter by replacing
>> HashMap with EnumMap in scenarios where the keys are exclusively ChronoField
>> enum values.
>>
>> When parsing date/time strings, DateTimeFormatter creates HashMaps to store
>> intermediate parsed values. HashMap has more overhead for operations
>> compared to specialized map implementations.
>>
>> Since ChronoField is an enum and all keys in these maps are ChronoField
>> instances, we can use EnumMap instead, which provides better performance for
>> enum keys due to its optimized internal structure.
>>
>> Parsing scenarios show improvements from 12% to 95%
>
> Shaojin Wen has updated the pull request incrementally with one additional
> commit since the last revision:
>
> remove redundant checkField
src/java.base/share/classes/java/time/format/DateTimeFormatter.java line 551:
> 549: * This is used to optimize the storage of parsed field values in
> the Parsed class.
> 550: */
> 551: final boolean onlyChronoField;
If you add to DateTimePrinterParser the method:
public default boolean onlyChronoFields() {
return true;
}
and override in CompositePrinterParser, NumberPrinterParser, TextPrinterParser,
DefaultValueParser with obvious implementations you should be able to get rid
of this field, same in DateTimeFormatterBuilder. (Or keep the field, but
initialize in the constructor from printerParser).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28471#discussion_r2626818693