Skip to content

Conversation

@wenshao
Copy link
Contributor

@wenshao wenshao commented Sep 13, 2023

In many scenarios, DateTimeFormatter::format is a slower operation.

For example, the following business scenarios

  1. The json library gson/jackson/fastjson2 formats Instant/LocalDate/LocalTime/LocalDateTime/ZonedDateTim into strings.
  2. In data integration scenarios, for projects like datax/canal, if the input type is Date/Instant and the output type is String, formatting is required.

This PR provides format performance optimization for commonly used date patterns.

ISO_INSTANT
ISO_LOCAL_TIME
ISO_LOCAL_DATE
ISO_LOCAL_DATETIME
HH:mm:ss
HH:mm:ss.SSS
yyyy-MM-dd
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss.SSS

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-8316235: Optimization for DateTimeFormatter::format (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15722

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 13, 2023

👋 Welcome back wenshao! 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 Sep 13, 2023

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

  • core-libs
  • i18n
  • security

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.

@openjdk openjdk bot added security security-dev@openjdk.org core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Sep 13, 2023
@wenshao
Copy link
Contributor Author

wenshao commented Sep 13, 2023

Performance comparison data is as follows:

1. Script

bash configure
make images
sh make/devkit/createJMHBundle.sh
bash configure --with-jmh=build/jmh/jars
make test TEST="micro:java.time.format.DateTimeFormatterBench.*"

2. MacBookPro benchmark

-Benchmark                                                   (pattern)   Mode  Cnt   Score   Error   Units (baseline)
-DateTimeFormatterBench.formatInstants                        HH:mm:ss  thrpt   15  14.888 ? 0.109  ops/ms
-DateTimeFormatterBench.formatInstants                    HH:mm:ss.SSS  thrpt   15  10.132 ? 0.046  ops/ms
-DateTimeFormatterBench.formatInstants           yyyy-MM-dd'T'HH:mm:ss  thrpt   15   8.993 ? 0.039  ops/ms
-DateTimeFormatterBench.formatInstants       yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt   15   7.400 ? 0.035  ops/ms
-DateTimeFormatterBench.formatZonedDateTime                   HH:mm:ss  thrpt   15  21.460 ? 0.056  ops/ms
-DateTimeFormatterBench.formatZonedDateTime               HH:mm:ss.SSS  thrpt   15  14.439 ? 0.264  ops/ms
-DateTimeFormatterBench.formatZonedDateTime      yyyy-MM-dd'T'HH:mm:ss  thrpt   15  12.742 ? 0.055  ops/ms
-DateTimeFormatterBench.formatZonedDateTime  yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt   15   9.059 ? 0.124  ops/ms

+Benchmark                                                   (pattern)   Mode  Cnt   Score   Error   Units (optimized)
+DateTimeFormatterBench.formatInstants                        HH:mm:ss  thrpt   15  28.082 ? 0.284  ops/ms (+88.62%)
+DateTimeFormatterBench.formatInstants                    HH:mm:ss.SSS  thrpt   15  25.483 ? 0.109  ops/ms (+151.51%)
+DateTimeFormatterBench.formatInstants           yyyy-MM-dd'T'HH:mm:ss  thrpt   15  19.950 ? 0.444  ops/ms (+121.83%)
+DateTimeFormatterBench.formatInstants       yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt   15  18.391 ? 0.327  ops/ms (+148.52%)
+DateTimeFormatterBench.formatZonedDateTime                   HH:mm:ss  thrpt   15  57.870 ? 0.641  ops/ms (+169.66%)
+DateTimeFormatterBench.formatZonedDateTime               HH:mm:ss.SSS  thrpt   15  43.783 ? 0.300  ops/ms (+203.22%)
+DateTimeFormatterBench.formatZonedDateTime      yyyy-MM-dd'T'HH:mm:ss  thrpt   15  36.220 ? 0.194  ops/ms (+184.25%)
+DateTimeFormatterBench.formatZonedDateTime  yyyy-MM-dd'T'HH:mm:ss.SSS  thrpt   15  32.512 ? 0.583  ops/ms (+258.89%)

@wenshao wenshao changed the title Optimization for DateTimeFormatter::format 8316235: Optimization for DateTimeFormatter::format Sep 14, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 14, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 14, 2023

Webrevs

@wenshao
Copy link
Contributor Author

wenshao commented Sep 16, 2023

/label remove i18n

@openjdk openjdk bot removed the i18n i18n-dev@openjdk.org label Sep 16, 2023
@openjdk
Copy link

openjdk bot commented Sep 16, 2023

@wenshao
The i18n label was successfully removed.

@wenshao
Copy link
Contributor Author

wenshao commented Sep 16, 2023

/label remove security

@openjdk openjdk bot removed the security security-dev@openjdk.org label Sep 16, 2023
@openjdk
Copy link

openjdk bot commented Sep 16, 2023

@wenshao
The security label was successfully removed.

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 14, 2023

@wenshao This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 12, 2023

@wenshao This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants