RFR: 8306374: (bf) Improve performance of DirectCharBuffer::append(CharSequence[,int,int])

Brian Burkhalter bpb at openjdk.org
Wed Apr 19 15:45:48 UTC 2023


On Wed, 19 Apr 2023 15:34:09 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Use `getChars()` to copy characters to an intermediate local `char[]` array and then `putArray()` to copy the chars into the buffer itself.
>
> src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template line 461:
> 
>> 459:             throw new BufferOverflowException();
>> 460: 
>> 461:         char[] buf = new char[APPEND_BUF_SIZE];
> 
> Can we do Math.min(length, APPEND_BUF_SIZE) here?

Yes.

> src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template line 489:
> 
>> 487:     public $Type$Buffer append(CharSequence csq) {
>> 488: #if[rw] 
>> 489:         if (csq instanceof StringBuilder) 
> 
> Why don't we check for string or stringbuffer here?

In the development of #13415 we found that those cases were not improved by the heap buffer override, but I think you are correct in that that change should also be measured before we throw it out.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13522#discussion_r1171528354
PR Review Comment: https://git.openjdk.org/jdk/pull/13522#discussion_r1171532027


More information about the nio-dev mailing list