RFR: 8263038: Optimize String.format for simple specifiers
Claes Redestad
redestad at openjdk.java.net
Thu Mar 4 17:46:56 UTC 2021
On Thu, 4 Mar 2021 17:20:40 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> This patch optimizes String.format expressions that uses trivial specifiers. In the JDK, the most common variation of String.format is a variation of format("foo: %s", s), which gets a significant speed-up from this.
>
> Various other cleanups and minor improvements reduce overhead further and ensure we get a small gain also for more complex format strings.
Microbench results - baseline:
Benchmark Mode Cnt Score Error Units
StringFormat.complexFormat avgt 5 8842.917 ± 658.269 ns/op
StringFormat.complexFormat:·gc.alloc.rate.norm avgt 5 2176.378 ± 0.483 B/op
StringFormat.stringFormat avgt 5 859.863 ± 97.514 ns/op
StringFormat.stringFormat:·gc.alloc.rate.norm avgt 5 560.091 ± 0.011 B/op
StringFormat.stringIntFormat avgt 5 1619.772 ± 147.646 ns/op
StringFormat.stringIntFormat:·gc.alloc.rate.norm avgt 5 728.132 ± 0.140 B/op
StringFormat.widthStringFormat avgt 5 1060.200 ± 154.025 ns/op
StringFormat.widthStringFormat:·gc.alloc.rate.norm avgt 5 592.108 ± 0.093 B/op
StringFormat.widthStringIntFormat avgt 5 2045.215 ± 246.189 ns/op
StringFormat.widthStringIntFormat:·gc.alloc.rate.norm avgt 5 784.144 ± 0.121 B/op
Patched:
Benchmark Mode Cnt Score Error Units
StringFormat.complexFormat avgt 5 8023.314 ± 1387.475 ns/op
StringFormat.complexFormat:·gc.alloc.rate.norm avgt 5 2120.399 ± 0.417 B/op
StringFormat.stringFormat avgt 5 286.776 ± 30.645 ns/op
StringFormat.stringFormat:·gc.alloc.rate.norm avgt 5 256.044 ± 0.017 B/op
StringFormat.stringIntFormat avgt 5 626.083 ± 68.652 ns/op
StringFormat.stringIntFormat:·gc.alloc.rate.norm avgt 5 432.073 ± 0.039 B/op
StringFormat.widthStringFormat avgt 5 1061.631 ± 156.444 ns/op
StringFormat.widthStringFormat:·gc.alloc.rate.norm avgt 5 560.103 ± 0.106 B/op
StringFormat.widthStringIntFormat avgt 5 1380.208 ± 267.445 ns/op
StringFormat.widthStringIntFormat:·gc.alloc.rate.norm avgt 5 736.134 ± 0.144 B/op
-Xint similarly sees no change on complexString, but a 3-3.5x speed-up on stringFormat
-------------
PR: https://git.openjdk.java.net/jdk/pull/2830
More information about the core-libs-dev
mailing list