On Sat, 29 Jun 2024 17:41:47 GMT, David Schlosnagle <d...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/StringFormat.java line 82: >> >>> 80: conv = format.charAt(off + 2); >>> 81: } >>> 82: } >> >> is it worth handling `width > 9`? >> >> Suggestion: >> >> for (int i = 2; conv >= '1' && conv <= '9' && off + i < max; i++) { >> width = (width * 10) + (conv - '0'); >> if (off + i < max) { >> conv = format.charAt(off + i); >> } >> } > > a quick local benchmark on 2021 MacBook M1 Pro before/after motivating this: > > > @Benchmark > public String wideStringIntFormat() { > return "%123s %42d".formatted(s, i); > } > > > #### Before: > > Benchmark Mode Cnt Score Error Units > StringFormat.wideStringIntFormat avgt 15 377.603 ± 85.742 ns/op > > > #### After: > > Benchmark Mode Cnt Score Error Units > StringFormat.wideStringIntFormat avgt 15 54.104 ± 0.079 ns/op But this is a fastpath optimization, is width > 9 common enough? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/19956#discussion_r1659951995