lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r610858 - /lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
Date Thu, 10 Jan 2008 18:11:54 GMT
Author: mikemccand
Date: Thu Jan 10 10:11:53 2008
New Revision: 610858

URL: http://svn.apache.org/viewvc?rev=610858&view=rev
Log:
LUCENE-1125: fix over-zero-filling that was drastically slowing down small docs w/ term vectors

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=610858&r1=610857&r2=610858&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java Thu Jan 10 10:11:53
2008
@@ -2768,10 +2768,26 @@
     public int byteOffset = -BYTE_BLOCK_SIZE;          // Current head offset
 
     public void reset() {
-      recycleByteBlocks(buffers, 1+bufferUpto);
-      bufferUpto = -1;
-      byteUpto = BYTE_BLOCK_SIZE;
-      byteOffset = -BYTE_BLOCK_SIZE;
+      if (bufferUpto != -1) {
+        // We allocated at least one buffer
+
+        for(int i=0;i<bufferUpto;i++)
+          // Fully zero fill buffers that we fully used
+          Arrays.fill(buffers[i], (byte) 0);
+
+        // Partial zero fill the final buffer
+        Arrays.fill(buffers[bufferUpto], 0, byteUpto, (byte) 0);
+          
+        if (bufferUpto > 0)
+          // Recycle all but the first buffer
+          recycleByteBlocks(buffers, 1, 1+bufferUpto);
+
+        // Re-use the first buffer
+        bufferUpto = 0;
+        byteUpto = 0;
+        byteOffset = 0;
+        buffer = buffers[0];
+      }
     }
 
     public void nextBuffer() {
@@ -2782,7 +2798,6 @@
         buffers = newBuffers;
       }
       buffer = buffers[bufferUpto] = getByteBlock();
-      Arrays.fill(buffer, (byte) 0);
 
       byteUpto = 0;
       byteOffset += BYTE_BLOCK_SIZE;
@@ -2954,10 +2969,10 @@
   }
 
   /* Return a byte[] to the pool */
-  synchronized void recycleByteBlocks(byte[][] blocks, int numBlocks) {
-    for(int i=0;i<numBlocks;i++)
+  synchronized void recycleByteBlocks(byte[][] blocks, int start, int end) {
+    for(int i=start;i<end;i++)
       freeByteBlocks.add(blocks[i]);
-    numBytesUsed -= numBlocks * BYTE_BLOCK_SIZE;
+    numBytesUsed -= (end-start) * BYTE_BLOCK_SIZE;
   }
 
   /* Initial chunk size of the shared char[] blocks used to



Mime
View raw message