On Fri, 17 Feb 2023 09:50:16 GMT, Sergey Tsypanov <stsypa...@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);
>     }
> }

Benchmarking

make test TEST="micro:time.format.ZonedDateTimeFormatterBenchmark" 
MICRO="OPTIONS=-prof gc"

master

Benchmark                                                              Mode  
Cnt      Score     Error   Units
ZonedDateTimeFormatterBenchmark.parse                                  avgt   
20  13545.737 ± 451.164   ns/op
ZonedDateTimeFormatterBenchmark.parse:·gc.alloc.rate                   avgt   
20   1713.579 ±  56.517  MB/sec
ZonedDateTimeFormatterBenchmark.parse:·gc.alloc.rate.norm              avgt   
20  24320.006 ±   0.001    B/op
ZonedDateTimeFormatterBenchmark.parse:·gc.count                        avgt   
20    110.000            counts
ZonedDateTimeFormatterBenchmark.parse:·gc.time                         avgt   
20    514.000                ms


patch

Benchmark                                                              Mode  
Cnt     Score    Error   Units
ZonedDateTimeFormatterBenchmark.parse                                  avgt   
20  1276.063 ± 52.543   ns/op
ZonedDateTimeFormatterBenchmark.parse:·gc.alloc.rate                   avgt   
20   622.223 ± 26.456  MB/sec
ZonedDateTimeFormatterBenchmark.parse:·gc.alloc.rate.norm              avgt   
20   832.001 ±  0.001    B/op
ZonedDateTimeFormatterBenchmark.parse:·gc.count                        avgt   
20    58.000           counts
ZonedDateTimeFormatterBenchmark.parse:·gc.time                         avgt   
20   475.000               ms

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

PR Comment: https://git.openjdk.org/jdk/pull/12612#issuecomment-1483893997

Reply via email to