On Fri, 31 Jan 2025 10:29:53 GMT, Shaojin Wen <s...@openjdk.org> wrote:
> By using the Class File API to dynamically generate a CompositePrinterParser, > and defining DateTimePrinterParser[] printerParsers as a specific field, C2 > can do TypeProfile optimization. > > Since the CompositePrinterParser is generated based on the pattern, we can > make the following optimizations: > > 1. For example, for the parse and print of > Month/DayOfMonth/Hour/Minute/Second with a fixed length of 2, do targeted > parse and print optimization. > > 2. Parse uses LocalDate/LocalTime/LocalDateTime/OffsetDateTime for > TemporalQuery to avoid the overhead of constructing DateTimeParseContext. > > These optimizations can significantly improve performance, with more than > 100% performance improvement in many scenarios. Below are the performance numbers on the MacBook M1, which show very significant performance improvements in both parse and format scenarios. Many scenarios have an improvement of more than 100%, and in parse, some scenarios have a performance improvement of more than 10 times. # 1. Script git remote add wenshao g...@github.com:wenshao/jdk.git git fetch wenshao #baseline git checkout 75caf4f7c6acf04d4acbe6434ecdc9ce9a6b35d7 make test TEST="micro:java.time.format.DateTimeFormatterParse" make test TEST="micro:java.time.format.DateTimeFormatterBench" # current git checkout 55ac19d6dfc401d66bb141ada501945b8145c62e make test TEST="micro:java.time.format.DateTimeFormatterParse" make test TEST="micro:java.time.format.DateTimeFormatterBench" # 2. the performance benchmarks on MacBook M1 Pro -# baseline -Benchmark (pattern) Mode Cnt Score Error Units (c49dd5b8efd) -DateTimeFormatterBench.formatInstants HH:mm:ss thrpt 15 16.326 ? 0.440 ops/ms -DateTimeFormatterBench.formatInstants HH:mm:ss.SSS thrpt 15 10.870 ? 0.080 ops/ms -DateTimeFormatterBench.formatInstants yyyy-MM-dd'T'HH:mm:ss thrpt 15 9.187 ? 0.374 ops/ms -DateTimeFormatterBench.formatInstants yyyy-MM-dd'T'HH:mm:ss.SSS thrpt 15 7.086 ? 0.235 ops/ms -DateTimeFormatterBench.formatZonedDateTime HH:mm:ss thrpt 15 23.344 ? 0.297 ops/ms -DateTimeFormatterBench.formatZonedDateTime HH:mm:ss.SSS thrpt 15 16.015 ? 0.198 ops/ms -DateTimeFormatterBench.formatZonedDateTime yyyy-MM-dd'T'HH:mm:ss thrpt 15 13.561 ? 0.527 ops/ms -DateTimeFormatterBench.formatZonedDateTime yyyy-MM-dd'T'HH:mm:ss.SSS thrpt 15 10.241 ? 0.055 ops/ms +# current +Benchmark (pattern) Mode Cnt Score Error Units (55ac19d6dfc) +DateTimeFormatterBench.formatInstants HH:mm:ss thrpt 15 44.066 ? 0.526 ops/ms +DateTimeFormatterBench.formatInstants HH:mm:ss.SSS thrpt 15 31.789 ? 0.124 ops/ms +DateTimeFormatterBench.formatInstants yyyy-MM-dd'T'HH:mm:ss thrpt 15 29.527 ? 0.090 ops/ms +DateTimeFormatterBench.formatInstants yyyy-MM-dd'T'HH:mm:ss.SSS thrpt 15 23.733 ? 0.083 ops/ms +DateTimeFormatterBench.formatZonedDateTime HH:mm:ss thrpt 15 116.871 ? 1.173 ops/ms +DateTimeFormatterBench.formatZonedDateTime HH:mm:ss.SSS thrpt 15 75.032 ? 0.321 ops/ms +DateTimeFormatterBench.formatZonedDateTime yyyy-MM-dd'T'HH:mm:ss thrpt 15 64.843 ? 0.633 ops/ms +DateTimeFormatterBench.formatZonedDateTime yyyy-MM-dd'T'HH:mm:ss.SSS thrpt 15 49.958 ? 0.511 ops/ms | | pattern | baseline | current | delta | | --- | --- | --- | --- | --- | | DateTimeFormatterBench.formatInstants | HH:mm:ss | 16.326 | 44.066 | 169.91% | | DateTimeFormatterBench.formatInstants | HH:mm:ss.SSS | 10.870 | 31.789 | 192.45% | | DateTimeFormatterBench.formatInstants | yyyy-MM-dd'T'HH:mm:ss | 9.187 | 29.527 | 221.40% | | DateTimeFormatterBench.formatInstants | yyyy-MM-dd'T'HH:mm:ss.SSS | 7.086 | 23.733 | 234.93% | | DateTimeFormatterBench.formatZonedDateTime | HH:mm:ss | 23.344 | 116.871 | 400.65% | | DateTimeFormatterBench.formatZonedDateTime | HH:mm:ss.SSS | 16.015 | 75.032 | 368.51% | | DateTimeFormatterBench.formatZonedDateTime | yyyy-MM-dd'T'HH:mm:ss | 13.561 | 64.843 | 378.16% | | DateTimeFormatterBench.formatZonedDateTime | yyyy-MM-dd'T'HH:mm:ss.SSS | 10.241 | 49.958 | 387.82% | -# baseline -Benchmark Mode Cnt Score Error Units (c49dd5b8efd) -DateTimeFormatterParse.parseInstant thrpt 15 2271.484 ? 114.069 ops/ms -DateTimeFormatterParse.parseLocalDate thrpt 15 6729.739 ? 1800.372 ops/ms -DateTimeFormatterParse.parseLocalDateTime thrpt 15 4224.068 ? 153.198 ops/ms -DateTimeFormatterParse.parseLocalDateTimeWithNano thrpt 15 4180.456 ? 82.478 ops/ms -DateTimeFormatterParse.parseLocalTime thrpt 15 4908.282 ? 208.797 ops/ms -DateTimeFormatterParse.parseLocalTimeWithNano thrpt 15 5412.657 ? 133.999 ops/ms -DateTimeFormatterParse.parseOffsetDateTime thrpt 15 2788.254 ? 85.754 ops/ms -DateTimeFormatterParse.parseZonedDateTime thrpt 15 2032.773 ? 78.660 ops/ms +# current +Benchmark Mode Cnt Score Error Units (55ac19d6dfc) +DateTimeFormatterParse.parseInstant thrpt 15 3645.826 ? 53.758 ops/ms +DateTimeFormatterParse.parseLocalDate thrpt 15 57592.249 ? 3711.524 ops/ms +DateTimeFormatterParse.parseLocalDateTime thrpt 15 24713.840 ? 1462.137 ops/ms +DateTimeFormatterParse.parseLocalDateTimeWithNano thrpt 15 15246.892 ? 960.591 ops/ms +DateTimeFormatterParse.parseLocalTime thrpt 15 115757.021 ? 15040.874 ops/ms +DateTimeFormatterParse.parseLocalTimeWithNano thrpt 15 64888.840 ? 297.881 ops/ms +DateTimeFormatterParse.parseOffsetDateTime thrpt 15 15789.014 ? 188.675 ops/ms +DateTimeFormatterParse.parseZonedDateTime thrpt 15 2313.851 ? 61.707 ops/ms | | baseline | current | delta | | --- | --- | --- | --- | | DateTimeFormatterParse.parseInstant | 2271.484 | 3645.826 | 60.50% | | DateTimeFormatterParse.parseLocalDate | 6729.739 | 57592.249 | 755.79% | | DateTimeFormatterParse.parseLocalDateTime | 4224.068 | 24713.840 | 485.07% | | DateTimeFormatterParse.parseLocalDateTimeWithNano | 4180.456 | 15246.892 | 264.72% | | DateTimeFormatterParse.parseLocalTime | 4908.282 | 115757.021 | 2258.40% | | DateTimeFormatterParse.parseLocalTimeWithNano | 5412.657 | 64888.840 | 1098.84% | | DateTimeFormatterParse.parseOffsetDateTime | 2788.254 | 15789.014 | 466.27% | | DateTimeFormatterParse.parseZonedDateTime | 2032.773 | 2313.851 | 13.83% | ------------- PR Comment: https://git.openjdk.org/jdk/pull/23384#issuecomment-2629267435