<i18n dev> RFR: 8372460: Use EnumMap instead of HashMap for DateTimeFormatter parsing to improve performance
Shaojin Wen
swen at openjdk.org
Tue Nov 25 06:32:34 UTC 2025
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%
-------------
Commit messages:
- bug fix, form @liach
- use EnumMap
- add benchmark
Changes: https://git.openjdk.org/jdk/pull/28471/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28471&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8372460
Stats: 153 lines in 5 files changed: 149 ins; 0 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/28471.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28471/head:pull/28471
PR: https://git.openjdk.org/jdk/pull/28471
More information about the i18n-dev
mailing list