-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8372460: Use EnumMap instead of HashMap for DateTimeFormatter parsing to improve performance #28936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8372460: Use EnumMap instead of HashMap for DateTimeFormatter parsing to improve performance #28936
Conversation
… 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.
|
👋 Welcome back rriggs! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@RogerRiggs The following labels will be automatically applied to this pull request:
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. |
liach
left a comment
There was a problem hiding this 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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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)?
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
Issue
Reviewers without OpenJDK IDs
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28936/head:pull/28936$ git checkout pull/28936Update a local copy of the PR:
$ git checkout pull/28936$ git pull https://git.openjdk.org/jdk.git pull/28936/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28936View PR using the GUI difftool:
$ git pr show -t 28936Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28936.diff