summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYunjie Li <yunjieli@google.com>2020-06-17 11:58:18 -0700
committerYunjie Li <yunjieli@google.com>2020-06-18 12:36:42 -0700
commitb94758441dd6f9fecc4946d21382aa03f6485c07 (patch)
treebb1c6c6dd37489cc6abf9a57d3251dfca70c4c63
parentc3db32d51ac8ca8d58d88a265b03d1e64b14e82f (diff)
downloadjgit-b94758441dd6f9fecc4946d21382aa03f6485c07.tar.gz
jgit-b94758441dd6f9fecc4946d21382aa03f6485c07.zip
PackBitmapIndex: Not buffer inflated bitmap during bitmap creation.
Currently we're buffering the inflated bitmap entry in BasePackBitmapIndex to optimize running time. However, this will use lots of memory during the creation of the pack bitmap index file. And change 161456, which rewrote the entire getBitmap method, increased the fetch latency significantly. This commit introduces getBitmapWithoutCaching method which is used in the pack bitmap index file creation only and aims to save memory during garbage collection and not increase fetch latency. Change-Id: I7b982c9d4e38f5f6193eaa03894e894ba992b33b Signed-off-by: Yunjie Li <yunjieli@google.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BasePackBitmapIndex.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java3
2 files changed, 17 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BasePackBitmapIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BasePackBitmapIndex.java
index c9bb167f02..ec53818b4e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BasePackBitmapIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BasePackBitmapIndex.java
@@ -59,12 +59,26 @@ abstract class BasePackBitmapIndex extends PackBitmapIndex {
* @return the full bitmap
*/
EWAHCompressedBitmap getBitmap() {
+ EWAHCompressedBitmap bitmap = getBitmapWithoutCaching();
+ // Cache the result.
+ bitmapContainer = bitmap;
+ return bitmap;
+ }
+
+ /**
+ * Compute and return the full bitmap, do NOT cache the expanded bitmap,
+ * which saves memory and should only be used during bitmap creation in
+ * garbage collection.
+ *
+ * @return the full bitmap
+ */
+ EWAHCompressedBitmap getBitmapWithoutCaching() {
// Fast path to immediately return the expanded result.
Object r = bitmapContainer;
if (r instanceof EWAHCompressedBitmap)
return (EWAHCompressedBitmap) r;
- // Expand the bitmap and cache the result.
+ // Expand the bitmap but not cache the result.
XorCompressedBitmap xb = (XorCompressedBitmap) r;
EWAHCompressedBitmap out = xb.bitmap;
for (;;) {
@@ -72,7 +86,6 @@ abstract class BasePackBitmapIndex extends PackBitmapIndex {
if (r instanceof EWAHCompressedBitmap) {
out = out.xor((EWAHCompressedBitmap) r);
out.trim();
- bitmapContainer = out;
return out;
}
xb = (XorCompressedBitmap) r;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java
index 4b25284517..dd5d03c6e9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java
@@ -156,7 +156,8 @@ public class PackBitmapIndexRemapper extends PackBitmapIndex
return null;
inflated.clear();
- for (IntIterator i = oldBitmap.getBitmap().intIterator(); i.hasNext();)
+ for (IntIterator i = oldBitmap.getBitmapWithoutCaching()
+ .intIterator(); i.hasNext();)
inflated.set(prevToNewMapping[i.next()]);
bitmap = inflated.toEWAHCompressedBitmap();
bitmap.trim();