RFR: 8315999: Improve Date toString performance [v13]

温绍锦 duke at openjdk.org
Sun Sep 24 08:23:16 UTC 2023


On Tue, 19 Sep 2023 16:27:50 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

> Lots of adhoc changes bulk up the source and make it less maintainable. Given the common element of time and date formatting strings as a domain specific language, there would be more benefit to leveraging one of several existing mechanisms to generate optimized formatters from application or library format strings. For example, the general purpose [JEP 430: String Template](https://openjdk.org/jeps/430)s could be used to compose the string and leverage its optimizations of formatting the components. Making improvements there either to performance or functionality would benefit more applications.
> 
> This also applies to [PR#15722](https://github.com/openjdk/jdk/pull/15722).

I submitted PR #15776 (Regex-free parsing of Formatter and FormatProcessor specifiers) to optimize the parse performance of String.format and StringFormatter. I submitted another PR #15699, the refactored code is related to String Template. 
After these two PRs are completed, I will continue to optimize java.util.Formatter.print and improve the performance of String.format and StringTemplate.

However, String.format and StringTemplate are different scenarios from this PR and PR#15722. Date/LocalDateTime/Instant#toString and DateTimeFormatter#format are very widely used, more widely used than String.format(Date/LocalDateTme/Instant). These Usage scenarios usually don't use String.format and StringTemplate instead.

The performance of using String.format and StringTemplate is not as good as using formatter and toString directly.

If you feel that the maintainability of these codes is not good enough, for example, we should reduce the use of ByteArrayLittleEndian, I can continue to improve these.

Because Date/LocalDateTime/Instant#toString and DateTimeFormatter#format are so widely used, I have also seen these methods taking a lot of time in flame graphs in business systems. I submitted this PR based on my business system optimization experience, so The optimization will directly improve the performance of the business system in certain scenarios.

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

PR Comment: https://git.openjdk.org/jdk/pull/15658#issuecomment-1732518234


More information about the core-libs-dev mailing list