You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2019/11/26 12:58:58 UTC

[lucene-solr] 01/02: LUCENE-9059: Reduce garbage created by ByteBuffersDataOutput. (#1031)

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit f76f4eaff87d97ea6cfcfa6ec629881ba0c88e75
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Tue Nov 26 11:41:11 2019 +0100

    LUCENE-9059: Reduce garbage created by ByteBuffersDataOutput. (#1031)
---
 .../org/apache/lucene/store/ByteBuffersDataOutput.java     | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java
index 9bdddd8..b4b4dd6 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java
@@ -21,7 +21,7 @@ import java.io.UncheckedIOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
@@ -279,11 +279,13 @@ public final class ByteBuffersDataOutput extends DataOutput implements Accountab
    * Copy the current content of this object into another {@link DataOutput}.
    */
   public void copyTo(DataOutput output) throws IOException {
-    for (ByteBuffer bb : toBufferList()) {
+    for (ByteBuffer bb : blocks) {
       if (bb.hasArray()) {
-        output.writeBytes(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining());
+        output.writeBytes(bb.array(), bb.arrayOffset(), bb.position());
       } else {
-        output.copyBytes(new ByteBuffersDataInput(Arrays.asList(bb)), bb.remaining());
+        bb = bb.asReadOnlyBuffer();
+        bb.flip();
+        output.copyBytes(new ByteBuffersDataInput(Collections.singletonList(bb)), bb.remaining());
       }
     }
   }
@@ -412,7 +414,9 @@ public final class ByteBuffersDataOutput extends DataOutput implements Accountab
    * lead to hard-to-debug issues, use with great care.
    */
   public void reset() {
-    blocks.stream().forEach(blockReuse);
+    if (blockReuse != NO_REUSE) {
+      blocks.forEach(blockReuse);
+    }
     blocks.clear();
     currentBlock = EMPTY;
   }