<i18n dev> Integrated: 8276220: Reduce excessive allocations in DateTimeFormatter

Claes Redestad redestad at openjdk.java.net
Wed Nov 3 23:00:21 UTC 2021


On Mon, 1 Nov 2021 13:04:20 GMT, Claes Redestad <redestad at openjdk.org> wrote:

> Prompted by a request from Volkan Yazıcı I took a look at why the java.time formatters are less efficient for some common patterns than custom formatters in apache-commons and log4j. This patch reduces the gap, without having looked at the third party implementations. 
> 
> When printing times:
> - Avoid turning integral values into `String`s before appending them to the buffer 
> - Specialize `appendFraction` for `NANO_OF_SECOND` to avoid use of `BigDecimal`
> 
> This means a speed-up and reduction in allocations when formatting almost any date or time pattern, and especially so when including sub-second parts (`S-SSSSSSSSS`).
> 
> Much of the remaining overhead can be traced to the need to create a `DateTimePrintContext` and adjusting `Instant`s into a `ZonedDateTime` internally. We could likely also win performance by specializing some common patterns.
> 
> Testing: tier1-3

This pull request has now been integrated.

Changeset: ce8c7670
Author:    Claes Redestad <redestad at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/ce8c76700ba854f43c48d32b068b30e7d78d9d1e
Stats:     564 lines in 4 files changed: 533 ins; 12 del; 19 mod

8276220: Reduce excessive allocations in DateTimeFormatter

Reviewed-by: scolebourne, naoto

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

PR: https://git.openjdk.java.net/jdk/pull/6188


More information about the i18n-dev mailing list