Jackie-Jiang commented on a change in pull request #7708: URL: https://github.com/apache/pinot/pull/7708#discussion_r743973727
########## File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/io/util/FixedByteValueReaderWriter.java ########## @@ -56,14 +57,28 @@ public String getUnpaddedString(int index, int numBytesPerValue, byte paddingByt assert buffer.length >= numBytesPerValue; long startOffset = (long) index * numBytesPerValue; - for (int i = 0; i < numBytesPerValue; i++) { - byte currentByte = _dataBuffer.getByte(startOffset + i); - if (currentByte == paddingByte) { - return new String(buffer, 0, i, UTF_8); + int written = 0; + long pattern = (paddingByte & 0xFFL) * 0x101010101010101L; + ByteBuffer wrapper = ByteBuffer.wrap(buffer); + for (int i = 0; i < ((numBytesPerValue >>> 3) << 3); i += 8) { Review comment: (minor) I think JVM will perform the optimization of only calculating `((numBytesPerValue >>> 3) << 3)` once, just leave a comment to confirm ########## File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/io/util/FixedByteValueReaderWriter.java ########## @@ -56,14 +57,28 @@ public String getUnpaddedString(int index, int numBytesPerValue, byte paddingByt assert buffer.length >= numBytesPerValue; long startOffset = (long) index * numBytesPerValue; - for (int i = 0; i < numBytesPerValue; i++) { - byte currentByte = _dataBuffer.getByte(startOffset + i); - if (currentByte == paddingByte) { - return new String(buffer, 0, i, UTF_8); + int written = 0; + long pattern = (paddingByte & 0xFFL) * 0x101010101010101L; + ByteBuffer wrapper = ByteBuffer.wrap(buffer); + for (int i = 0; i < ((numBytesPerValue >>> 3) << 3); i += 8) { + long word = _dataBuffer.getLong(startOffset + i); + wrapper.putLong(i, word); + long zeroed = word ^ pattern; + long tmp = (zeroed & 0x7F7F7F7F7F7F7F7FL) + 0x7F7F7F7F7F7F7F7FL; + tmp = ~(tmp | zeroed | 0x7F7F7F7F7F7F7F7FL); + int end = Long.numberOfLeadingZeros(tmp) >>> 3; Review comment: Will it be faster if we first check `if (tmp != 0)`? ```suggestion if (tmp != 0) { int end = Long.numberOfLeadingZeros(tmp) >>> 3; return new String(buffer, 0, written + end, UTF_8); } ``` We can also directly make this `for` loop on `written` -- 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