<i18n dev> RFR: 8304976: Optimize DateTimeFormatterBuilder.ZoneTextPrinterParser.getTree()

Naoto Sato naoto at openjdk.org
Tue Mar 28 16:44:26 UTC 2023


On Fri, 17 Feb 2023 09:50:16 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:

> 1) When `DateTimeFormatter` is reused we don't need to copy `availableZoneIds` and allocate `nonRegionIds` as PrefixTree can be taken from cache. In the related benchmark allocation of `HashSet` takes ~93% of all time, so avoiding it should bring some improvement for cases when we reuse `DateTimeFormatter` to parse a string into `ZoneDateTime`
> ![image](https://user-images.githubusercontent.com/10835776/219609028-af48eae4-d326-4719-8366-c215baa85835.png)
> 
> 2) `DateTimeFormatter` is mostly used with one locale, so `cachedTree` and `cachedTreeCI` can have predefined size.
> 
> 
> @State(Scope.Thread)
> @BenchmarkMode(Mode.AverageTime)
> @OutputTimeUnit(TimeUnit.NANOSECONDS)
> public class DateTimeFormatterBenchmark {
> 
>     private static final DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern("yyyy:MM:dd:HH:mm:v").toFormatter();
>     private static final String TEXT = "2015:03:10:12:13:ECT";
> 
>     @Setup
>     public void setUp() {
>         ZonedDateTime.parse(TEXT, df);
>     }
> 
>     @Benchmark
>     public ZonedDateTime parse() {
>         return ZonedDateTime.parse(TEXT, df);
>     }
> }

Looks like a nice fix to me.

test/micro/org/openjdk/bench/java/time/format/ZonedDateTimeFormatterBenchmark.java line 23:

> 21:  * questions.
> 22:  */
> 23: package time.format;

package should be `org.openjdk.bench.java.time.format`?

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

Changes requested by naoto (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/12612#pullrequestreview-1361520443
PR Review Comment: https://git.openjdk.org/jdk/pull/12612#discussion_r1150894573


More information about the i18n-dev mailing list