Skip to content

Conversation

@RogerRiggs
Copy link
Contributor

@RogerRiggs RogerRiggs commented Dec 19, 2025

Refactor java.time.format.Parsed to use an EnumMap<ChronoField,Long> by default and upgrade to a HashMap if any of the fields are not ChronoFields.
In the java.time implementation all of the fields used are ChronoField.
Unless the application introduces a custom TemporalField there is no additional overhead.

This an alternative to PR #28471


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8372460: Use EnumMap instead of HashMap for DateTimeFormatter parsing to improve performance (Enhancement - P4)

Reviewers without OpenJDK IDs

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28936/head:pull/28936
$ git checkout pull/28936

Update a local copy of the PR:
$ git checkout pull/28936
$ git pull https://git.openjdk.org/jdk.git pull/28936/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28936

View PR using the GUI difftool:
$ git pr show -t 28936

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28936.diff

… to improve performance

Refactor java.time.format.Parsed to use an EnumMap<ChronoField,Long> by default and upgrade
to a HashMap if any of the fields are not ChronoFields.
Except for tests all of the fields are ChronoFields.
@bridgekeeper
Copy link

bridgekeeper bot commented Dec 19, 2025

👋 Welcome back rriggs! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 19, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Dec 19, 2025

@RogerRiggs The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map is passed to TemporalField::resolve, so this approach is risky.


// A bit contorted way to get the map created.
@SuppressWarnings("unchecked")
private Map<TemporalField, Long> initFieldValuesMap() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Map<TemporalField, Long> initFieldValuesMap() {
private static Map<TemporalField, Long> initFieldValuesMap() {

Let's make this static to be early-construction safe.

return fieldValues.put(field, value);
} catch (ClassCastException cce) {
// Upgrade to a full TemporalField Map
Map<TemporalField, Long> nmap = new HashMap<>(fieldValues.size() + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Map<TemporalField, Long> nmap = new HashMap<>(fieldValues.size() + 1);
Map<TemporalField, Long> nmap = HashMap.newHashMap(fieldValues.size() + 1);

We might still anticipate more elements to be put into the map, so a better alternative might be just new HashMap<>(fieldValues)?

@RogerRiggs RogerRiggs closed this Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants