RFR: 8305811: (bf) Improve performance of CharBuffer::append(CharSequence[,int,int]) [v4]

Brian Burkhalter bpb at openjdk.org
Fri Apr 14 00:46:39 UTC 2023


On Thu, 13 Apr 2023 20:16:18 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 316:
>> 
>>> 314: #if[rw]
>>> 315:         if (csq instanceof StringBuilder sb)
>>> 316:             return append(sb, start, end);
>> 
>> Maybe try re‑adding variants for `StringBuffer` and `String` here in order to avoid substring allocations, and see if `CharBufferAppend.appendSubString` and `CharBufferAppend.appendSubStringBuffer` performance improves?
>
> I'll check it out.

The commit bf403f90bce165ad71e45a0372d22be4165c3e61 adds the use of `getChars()` when appending a subsequence of a `String` or `StringBuffer`. Avoiding substring allocation in fact improves performance as shown in these updated results:

Benchmark                                 Mode  Cnt        Score        Error  Units
CharBufferAppend.appendDirectToDirect    thrpt   10  4719216.266 ± 227330.627  ops/s
CharBufferAppend.appendDirectToHeap      thrpt   10  2102880.055 ±  55054.002  ops/s
CharBufferAppend.appendHeapToDirect      thrpt   10  2328149.744 ± 110434.431  ops/s
CharBufferAppend.appendHeapToHeap        thrpt   10  3227172.246 ±  79850.461  ops/s
CharBufferAppend.appendString            thrpt   10  4418599.392 ±  51612.735  ops/s
CharBufferAppend.appendStringBuffer      thrpt   10  4362670.418 ± 101017.472  ops/s
CharBufferAppend.appendStringBuilder     thrpt   10  3856127.917 ± 110625.008  ops/s
CharBufferAppend.appendSubString         thrpt   10  7913540.253 ±  84487.457  ops/s
CharBufferAppend.appendSubStringBuffer   thrpt   10  8284545.161 ± 102884.827  ops/s
CharBufferAppend.appendSubStringBuilder  thrpt   10  8258542.262 ±  94236.638  ops/s```

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1166160252


More information about the nio-dev mailing list