On Mon, 1 Dec 2025 02:33:33 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: > > bug fix Spreading out and duplicating the state across multiple classes isn't very satisfactory. Since non-ChronoField is very unlikely, I'd suggest a more localized change confined to Parsed. Always create the initial EnumMap and refactor the `fieldValues.put()` calls to a private utility method to catch the ClassCatchException and upgrade the map to a HashMap. That should retain the performance improvements without any extra overhead or non-local code changes for all of the normal cases. ------------- PR Comment: https://git.openjdk.org/jdk/pull/28471#issuecomment-3596762057
