Use EnumMap instead of HashMap for DateTimeFormatter parsing to improve performance
Chen Liang
chen.l.liang at oracle.com
Tue Nov 25 06:03:45 UTC 2025
I agree with this observation that most of the parsed or stored temporal fields are the built-in chrono fields. With this optimization, we might need to review our tests to ensure we won't run into crashes if we incorrectly assumed a parsing context has only chrono fields.
________________________________
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of wenshao <shaojin.wensj at alibaba-inc.com>
Sent: Monday, November 24, 2025 11:12 PM
To: core-libs-dev <core-libs-dev at openjdk.org>
Subject: Use EnumMap instead of HashMap for DateTimeFormatter parsing to improve performance
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%.
To better express my ideas, I submitted a draft PR: https://github.com/openjdk/jdk/pull/28471 , and I hope you can give me feedback.
-
Shaojin Wen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20251125/0a279984/attachment.htm>
More information about the core-libs-dev
mailing list