On Wed, 3 Nov 2021 13:14:42 GMT, Claes Redestad <redes...@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
>
> Claes Redestad has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Add test verifying OOB values throw exception

Thanks for adding the new tests, and finding that fraction formatting is more 
constrained than I thought it was.

I think there is a case for a spec update in `DateTimeFormatterBuilder` to 
clarify the constraint on the input value (at this point, that seems better 
than changing the behaviour of fraction formatting). As things stand, the 
exception that is thrown is not described by the spec. (The spec change could 
be part of this PR or a separate one).

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

Marked as reviewed by scolebourne (Author).

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

Reply via email to