gortiz opened a new pull request, #11015: URL: https://github.com/apache/pinot/pull/11015
This is a simple PR that tries to reduce the amount of byte[] that are created by `GrpcSendingMailbox`. There are still some places that can be improved, but these changes are easy to apply and very effective. The main changes are: - To use `org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream` instead of `java.io.ByteArrayOutputStream`. As stated in the Javadoc, UnsynchronizedByteArrayOutputStream is a 1-1 replacement of `ByteArrayOutputStream`, but instead of doubling the size of the stored byte[], it starts to write into a new byte[]. Given that we are not going to read the `byte[]` later but just copy it with `toByteArray`, the apache common implementation is faster for us. Maybe we should work in our own implementation that works like STD ByteArrayOutputStream but does let us access the byte[] without copy (as we know it is safe) or even better, we may need to think on another way to serialize the information. - Try to initialize `UnsynchronizedByteArrayOutputStream` with closer to reality initial values. For example we know the exact number of bytes we need in `DataBlockBuilder._fixedSizeDataByteArrayOutputStream` - Reuse the ByteBuffer in `DataBlockBuilder.buildFromRows` instead of creating one per row - Change `GrpcSendingMailbox.toMailboxcContent` to do not call `ByteString.copyFrom` but `UnsafeByteOperations.unsafeWrap(bytes)`, which is _unsafe_ because the content should not be modified, but we provide there a fresh new byte[], so we know it won't. Some initial performance I made show a noticeable change in allocation. These flamegraphs have been obtained using async-profiler but executing the same queries the same number of times: Without optimization: 77.9 GBs allocated  With optiumization: 48 Gbs allocated  Labels: performance -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org