<i18n dev> RFR: 8337279: Optimize format instant [v2]

Stephen Colebourne scolebourne at openjdk.org
Sun Jul 28 13:39:31 UTC 2024


On Fri, 26 Jul 2024 15:44:59 GMT, Shaojin Wen <duke at openjdk.org> wrote:

>> By removing the redundant code logic in DateTimeFormatterBuilder$InstantPrinterParser#formatTo, the codeSize can be reduced and the performance can be improved.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   add comment

src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java line 3812:

> 3810:             int inNano = NANO_OF_SECOND.checkValidIntValue(inNanos != null ? inNanos : 0);
> 3811:             // use LocalDateTime.toString, If fractionalDigits < 0, printNano is implemented in LocalDateTime
> 3812:             LocalDateTime ldt = LocalDateTime.ofEpochSecond(inSecs, fractionalDigits >= 0 ? 0 : inNano, ZoneOffset.UTC);

I believe this whole approach is flawed. The comment above says:

`// use INSTANT_SECONDS, thus this code is not bound by Instant.MAX`

which indicates that the instant value may not fit in `LocalDateTime`.

You may be able to special case certain code paths to use `LocalDateTime`, but that makes things more complex, and not necessarily faster.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20353#discussion_r1694249198


More information about the i18n-dev mailing list