Jackie-Jiang 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_r303180771
 
 

 ##########
 File path: 
pinot-core/src/main/java/org/apache/pinot/core/io/util/VarLengthBytesValueReaderWriter.java
 ##########
 @@ -204,7 +226,25 @@ public double getDouble(int index) {
 
   @Override
   public String getUnpaddedString(int index, int numBytesPerValue, byte 
paddingByte, byte[] buffer) {
-    return StringUtil.decodeUtf8(getBytes(index, numBytesPerValue, buffer));
+    // Read the offset of the byte array first and then read the actual byte 
array.
+    int offset = _dataBuffer.getInt(_dataSectionStartOffSet + Integer.BYTES * 
index);
+
+    // 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;
+
+    byte[] b;
+    if (buffer != null && buffer.length >= length) {
+      b = buffer;
+    } else {
+      // Check if the current instance of ThreadLocal buffer is big enough. If 
not, resize it to double the size.
+      if (_reusableBytes.get().length < length) {
 
 Review comment:
   To save a `_reusableBytes.get()`:
   ```
   b = _reusableBytes.get();
   if (b.length < length) {
     b = new byte[nextPowerOf2(length)];
     _reusableBytes.set(b);
   }
   ```

----------------------------------------------------------------
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]

Reply via email to