RFR: 8315789: Minor HexFormat performance improvements
Claes Redestad
redestad at openjdk.org
Wed Sep 6 13:43:01 UTC 2023
This PR seeks to improve formatting of hex digits using `java.util.HexFormat` somewhat.
This is achieved getting rid of a couple of lookup tables, caching the result of `HexFormat.of().withUpperCase()`, and removing tiny allocation that happens in the `formatHex(A, byte)` method. Improvements range from 20-40% on throughput, and some operations allocate less:
Name Cnt Base Error Test Error Unit Diff%
HexFormatBench.appenderLower 15 1,330 ± 0,021 1,065 ± 0,067 us/op 19,9% (p = 0,000*)
:gc.alloc.rate 15 11,481 ± 0,185 0,007 ± 0,000 MB/sec -99,9% (p = 0,000*)
:gc.alloc.rate.norm 15 16,009 ± 0,000 0,007 ± 0,000 B/op -100,0% (p = 0,000*)
:gc.count 15 3,000 0,000 counts
:gc.time 3 2,000 ms
HexFormatBench.appenderLowerCached 15 1,317 ± 0,013 1,065 ± 0,054 us/op 19,1% (p = 0,000*)
:gc.alloc.rate 15 11,590 ± 0,111 0,007 ± 0,000 MB/sec -99,9% (p = 0,000*)
:gc.alloc.rate.norm 15 16,009 ± 0,000 0,007 ± 0,000 B/op -100,0% (p = 0,000*)
:gc.count 15 3,000 0,000 counts
:gc.time 3 2,000 ms
HexFormatBench.appenderUpper 15 1,330 ± 0,022 1,065 ± 0,036 us/op 19,9% (p = 0,000*)
:gc.alloc.rate 15 34,416 ± 0,559 0,007 ± 0,000 MB/sec -100,0% (p = 0,000*)
:gc.alloc.rate.norm 15 48,009 ± 0,000 0,007 ± 0,000 B/op -100,0% (p = 0,000*)
:gc.count 15 0,000 0,000 counts
HexFormatBench.appenderUpperCached 15 1,353 ± 0,009 1,033 ± 0,014 us/op 23,6% (p = 0,000*)
:gc.alloc.rate 15 11,284 ± 0,074 0,007 ± 0,000 MB/sec -99,9% (p = 0,000*)
:gc.alloc.rate.norm 15 16,009 ± 0,000 0,007 ± 0,000 B/op -100,0% (p = 0,000*)
:gc.count 15 3,000 0,000 counts
:gc.time 3 2,000 ms
HexFormatBench.toHexLower 15 0,198 ± 0,001 0,119 ± 0,008 us/op 40,1% (p = 0,000*)
:gc.alloc.rate 15 0,007 ± 0,000 0,007 ± 0,000 MB/sec -0,0% (p = 0,816 )
:gc.alloc.rate.norm 15 0,001 ± 0,000 0,001 ± 0,000 B/op -40,1% (p = 0,000*)
:gc.count 15 0,000 0,000 counts
HexFormatBench.toHexLowerCached 15 0,201 ± 0,002 0,114 ± 0,001 us/op 43,0% (p = 0,000*)
:gc.alloc.rate 15 0,007 ± 0,000 0,007 ± 0,000 MB/sec -0,2% (p = 0,116 )
:gc.alloc.rate.norm 15 0,001 ± 0,000 0,001 ± 0,000 B/op -43,1% (p = 0,000*)
:gc.count 15 0,000 0,000 counts
HexFormatBench.toHexUpper 15 0,146 ± 0,002 0,114 ± 0,001 us/op 21,6% (p = 0,000*)
:gc.alloc.rate 15 0,007 ± 0,000 0,007 ± 0,000 MB/sec 0,0% (p = 0,668 )
:gc.alloc.rate.norm 15 0,001 ± 0,000 0,001 ± 0,000 B/op -21,5% (p = 0,000*)
:gc.count 15 0,000 0,000 counts
HexFormatBench.toHexUpperCached 15 0,199 ± 0,002 0,116 ± 0,003 us/op 41,7% (p = 0,000*)
:gc.alloc.rate 15 0,007 ± 0,000 0,007 ± 0,000 MB/sec 0,0% (p = 0,684 )
:gc.alloc.rate.norm 15 0,001 ± 0,000 0,001 ± 0,000 B/op -41,7% (p = 0,000*)
:gc.count 15 0,000 0,000 counts
* = significant
Invariant parameters used by above microbenchmarks:
size: 512
-------------
Commit messages:
- 8315789: Minor HexFormat performance improvements
Changes: https://git.openjdk.org/jdk/pull/15591/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15591&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8315789
Stats: 184 lines in 2 files changed: 156 ins; 9 del; 19 mod
Patch: https://git.openjdk.org/jdk/pull/15591.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/15591/head:pull/15591
PR: https://git.openjdk.org/jdk/pull/15591
More information about the core-libs-dev
mailing list