Andrey Yarovoy created HDDS-15485:
-------------------------------------

             Summary: Avoid ByteBuffer.wrap on ChunkBuffer.put(byte[]) path
                 Key: HDDS-15485
                 URL: https://issues.apache.org/jira/browse/HDDS-15485
             Project: Apache Ozone
          Issue Type: Bug
            Reporter: Andrey Yarovoy


The default on {{ChunkBuffer}} is:
 
{code:java}

default ChunkBuffer put(byte[] b,int offset,int length) {
    return put(ByteBuffer.wrap(b, offset, length));   
}
 
{code}
So every {{{}put(byte[], offset, length){}}}:
 # Allocates a new {{ByteBuffer}} view ({{{}HeapByteBuffer{}}} over the same 
backing array).
 # Dispatches to {{put(ByteBuffer)}}, which for list/incremental buffers runs a 
segment loop that adjusts the wrapper’s position/limit and copies via 
{{{}ByteBuffer.put(ByteBuffer){}}}.

On the client write path, {{BlockOutputStream.write(byte[], …)}} calls 
{{currentBuffer.put(b, off, writeLen)}} once per slice that fits in the current 
chunk buffer. Large writes can do that many times per {{write()}} call.

 

{{wrap}} itself is “cheap” (no array copy), but per call it still pays object 
allocation + dispatch into the {{ByteBuffer}} put path. On a hot path called 
for every slice of every {{{}write(byte[]){}}}, that cost is measurable under 
load.

 

the fix would be micro-optimization, but should reduce memory allocations on 
hot path and reduce number of objects for garbage collection.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to