buchireddy commented on a change in pull request #4432: #4401 Reuse a
ThreadLocal byte[] when reading String elements from the variable length value
reader.
URL: https://github.com/apache/incubator-pinot/pull/4432#discussion_r303176683
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/io/util/VarLengthBytesValueReaderWriter.java
##########
@@ -220,13 +232,25 @@ public String getPaddedString(int index, int
numBytesPerValue, byte[] buffer) {
// To get the length of the byte array, we use the next byte array offset.
int length = _dataBuffer.getInt(_dataSectionStartOffSet + Integer.BYTES *
(index + 1)) - offset;
+ // Since the byte[] is returned to the caller and caller could hold a
reference to it,
+ // the buffer can't really be reused here. Hence, don't use ThreadLocal
buffer in this case.
+ return getBytes(buffer, offset, length, false);
+ }
+
+ private byte[] getBytes(byte[] buffer, int offset, int length, boolean
useThreadLocalBuffer) {
byte[] b;
- // If the caller didn't pass a buffer, create one with exact length.
- if (buffer == null) {
- b = new byte[length];
+ // If the caller has passed a buffer that can be used, use it.
+ if (buffer != null && buffer.length == length) {
Review comment:
I tried to reuse the code across two methods, which forces us to have the
`if` condition but I've now made the code simple with some duplication. Unit
tests should help us to catch any issues here too.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]