# Goal Improve String Template FMT's processing performance of date types. Currently, FMT processes date types by toString and then calls j.u.Formatter#print. Because there is less parse processing than String.format, the performance is improved, but it is still not good enough. There is an intermediate String object allocation, and the print performance of j.u.Formatter is not as good as The StringConcat.prepend method is great.
This patch allows String Template FMT to handle Date/Instant/LocalDate/LocalTime/LocalDateTime/OffsetTime/OffsetDateTime/ZonedDateTime/Instant types with optimization, just like int/long/float/double/String. # Optimized type and Specifier combinations * java.util.Date %s %tc (Sat Nov 04 12:02:33 EST 1999) %tD DATE (mm/dd/yy) %tF ISO_STANDARD_DATE (%Y-%m-%d) %tT TIME (24 hour hh:mm:ss) %tR TIME_24_HOUR hh:mm same as %H:%M %tr TIME_12_HOUR (hh:mm:ss [AP]M) * LocalDate %s %tD DATE (mm/dd/yy) %tF ISO_STANDARD_DATE (%Y-%m-%d) * LocalDateTime %s %tD DATE (mm/dd/yy) %tF ISO_STANDARD_DATE (%Y-%m-%d) %tT TIME (24 hour hh:mm:ss) %tR TIME_24_HOUR hh:mm same as %H:%M %tr TIME_12_HOUR (hh:mm:ss [AP]M) * OffsetDateTime %s %tD DATE (mm/dd/yy) %tF ISO_STANDARD_DATE (%Y-%m-%d) %tT TIME (24 hour hh:mm:ss) %tR TIME_24_HOUR hh:mm same as %H:%M %tr TIME_12_HOUR (hh:mm:ss [AP]M) * ZonedDateTime %s %tD DATE (mm/dd/yy) %tF ISO_STANDARD_DATE (%Y-%m-%d) %tT TIME (24 hour hh:mm:ss) %tR TIME_24_HOUR hh:mm same as %H:%M %tr TIME_12_HOUR (hh:mm:ss [AP]M) * LocalTime %s %tT TIME (24 hour hh:mm:ss) %tR TIME_24_HOUR hh:mm same as %H:%M %tr TIME_12_HOUR (hh:mm:ss [AP]M) * OffsetTime %s %tT TIME (24 hour hh:mm:ss) %tR TIME_24_HOUR hh:mm same as %H:%M %tr TIME_12_HOUR (hh:mm:ss [AP]M) * Instant %s # Performance Numbers run on MacBook M1 Pro -Benchmark Mode Cnt Score Error Units (baseline) -StringTemplateFMT.dateFormat avgt 15 66.601 ? 0.863 ns/op -StringTemplateFMT.instantFormat avgt 15 198.284 ? 5.804 ns/op -StringTemplateFMT.ldtFormat avgt 15 103.625 ? 6.315 ns/op -StringTemplateFMT.localTimeFormat avgt 15 44.750 ? 0.219 ns/op -StringTemplateFMT.zdtFormat avgt 15 179.140 ? 8.379 ns/op +Benchmark Mode Cnt Score Error Units (optimized) +StringTemplateFMT.dateFormat avgt 15 29.425 ? 0.510 ns/op (+126.35) +StringTemplateFMT.instantFormat avgt 15 36.467 ? 0.114 ns/op (+443.74) +StringTemplateFMT.ldtFormat avgt 15 27.208 ? 0.073 ns/op (+280.87) +StringTemplateFMT.localTimeFormat avgt 15 8.430 ? 0.017 ns/op (+430.85) +StringTemplateFMT.zdtFormat avgt 15 37.774 ? 0.135 ns/op (+374.25) # The next Use DateTimeUtils in the patch to refactor the toString methods of Date/Instant/LocalDate/LocalTime/LocalDateTime/OffsetTime/OffsetDateTime/ZonedDateTime/Instant to optimize performance and ensure consistency. ------------- Commit messages: - Merge remote-tracking branch 'upstream/master' into st_fmt_support_datetime - add copyright info - fix codestyle & merge two array (weeks & months) - String Template FMT built-in optimization for java.time.DateTimes Changes: https://git.openjdk.org/jdk/pull/16044/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16044&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8327429 Stats: 1775 lines in 14 files changed: 1769 ins; 0 del; 6 mod Patch: https://git.openjdk.org/jdk/pull/16044.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/16044/head:pull/16044 PR: https://git.openjdk.org/jdk/pull/16044