On Tue, 25 Nov 2025 06:44:57 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:
> 
>   copyright

I think instead of checking each component printer parser, we should check the 
public methods on `DateTimeFormatterBuilder` that can take a `TemporalField` 
and track the `onlyChronoField` there.

This is better because this is where users can actaully pass in 
non-ChronoField. For example, I last time discovered text printer parser, and 
now have discovered DefaultValueParser is problematic too.

So I believe guarding where users can pass custom TemporalField and adding a 
boolean field on a DateTimeFormatterBuilder to keep track of this is better.

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

Changes requested by liach (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28471#pullrequestreview-3521038435

Reply via email to