nfsantos commented on code in PR #1202: URL: https://github.com/apache/jackrabbit-oak/pull/1202#discussion_r1395776984
########## oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/PipelinedSortBatchTask.java: ########## @@ -116,48 +136,90 @@ public Result call() throws Exception { } } + private void buildSortArray(NodeStateEntryBatch nseb) { + Stopwatch startTime = Stopwatch.createStarted(); + ByteBuffer buffer = nseb.getBuffer(); + int totalPathSize = 0; + while (buffer.hasRemaining()) { + int positionInBuffer = buffer.position(); + // Read the next key from the buffer + int pathLength = buffer.getInt(); + totalPathSize += pathLength; + if (pathLength > copyBuffer.length) { + LOG.debug("Resizing copy buffer from {} to {}", copyBuffer.length, pathLength); + copyBuffer = new byte[pathLength]; + } + buffer.get(copyBuffer, 0, pathLength); + // Skip the json + int entryLength = buffer.getInt(); + buffer.position(buffer.position() + entryLength); + // Create the sort key + String path = new String(copyBuffer, 0, pathLength, StandardCharsets.UTF_8); + String[] pathSegments = SortKey.genSortKeyPathElements(path); Review Comment: I have changed the code to read directly from the ByteBuffer instead of copying to an intermediate buffer, that is, to do this: ``` new String(buff.array(), pos, len, StandardCharsets.UTF_8); ``` However, the proposed solution of writing to the byte buffer the path segments separately just moves the work of splitting the string with the path into segments from the sort-batch thread into the transform thread, and it would complicate somewhat reading and writing to the ByteBuffer, which instead of having two strings for each entry (path and json) would now have n strings for the path and 1 for the json. Therefore, I will leave it as it is. -- 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: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org