<i18n dev> RFR: 8316235: Optimization for DateTimeFormatter::format

温绍锦 duke at openjdk.org
Thu Sep 14 02:21:13 UTC 2023


On Wed, 13 Sep 2023 14:56:15 GMT, 温绍锦 <duke at openjdk.org> wrote:

> In many scenarios, DateTimeFormatter::format is a slower operation.  
> 
> For example, the following business scenarios
> 1. The json library gson/jackson/[fastjson2](https://github.com/alibaba/fastjson2) formats Instant/LocalDate/LocalTime/LocalDateTime/ZonedDateTim into strings.
> 2. In data integration scenarios, for projects like  [datax](https://github.com/alibaba/datax)/[canal](https://github.com/alibaba/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

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%)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15722#issuecomment-1717870613


More information about the i18n-dev mailing list