summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2023-11-10 12:05:51 -0800
committerIvan Frade <ifrade@google.com>2023-12-14 15:42:41 -0800
commite25bf957387b944dac0a12fe6e6ed8b284db81bb (patch)
treeb5693dadf7ae20956b7683de54981e126dd92dac /org.eclipse.jgit
parent52c18ae15f8fa3787f920e68791367dae2e1af2d (diff)
downloadjgit-e25bf957387b944dac0a12fe6e6ed8b284db81bb.tar.gz
jgit-e25bf957387b944dac0a12fe6e6ed8b284db81bb.zip
PackBitmapIndex/StoredBitmap: Expose size and counts
PackBitmapIndex holds a collection of StoredBitmaps. StoredBitmaps can be either base bitmaps (ready) or an XOR over another bitmap. XOR bitmaps are replaced with a resolved version on demand. Bitmaps can use a significant amount of memory but we don't have detailed visibility about it. Add methods to PackBitmapIndex to know how many xor/bases we have and their sizes. Change-Id: I57aa80a1f07ddf9223eb34cfda85aab85529ea9c
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BasePackBitmapIndex.java75
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java35
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java20
3 files changed, 129 insertions, 1 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 906faded81..c2b3926309 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
@@ -35,6 +35,50 @@ abstract class BasePackBitmapIndex extends PackBitmapIndex {
return bitmaps;
}
+ @Override
+ public int getBaseBitmapCount() {
+ int bases = 0;
+ for (StoredBitmap sb : getBitmaps()) {
+ if (sb.isBase()) {
+ bases += 1;
+ }
+ }
+ return bases;
+ }
+
+ @Override
+ public long getBaseBitmapSizeInBytes() {
+ long baseSize = 0;
+ for (StoredBitmap sb : getBitmaps()) {
+ if (sb.isBase()) {
+ baseSize += sb.getCurrentSizeInBytes();
+ }
+ }
+ return baseSize;
+ }
+
+ @Override
+ public int getXorBitmapCount() {
+ int xored = 0;
+ for (StoredBitmap sb : getBitmaps()) {
+ if (!sb.isBase()) {
+ xored += 1;
+ }
+ }
+ return xored;
+ }
+
+ @Override
+ public long getXorBitmapSizeInBytes() {
+ long xorSize = 0;
+ for (StoredBitmap sb : getBitmaps()) {
+ if (!sb.isBase()) {
+ xorSize += sb.getCurrentSizeInBytes();
+ }
+ }
+ return xorSize;
+ }
+
/**
* Data representation of the bitmap entry restored from a pack index. The
* commit of the bitmap is the map key.
@@ -74,8 +118,9 @@ abstract class BasePackBitmapIndex extends PackBitmapIndex {
EWAHCompressedBitmap getBitmapWithoutCaching() {
// Fast path to immediately return the expanded result.
Object r = bitmapContainer;
- if (r instanceof EWAHCompressedBitmap)
+ if (r instanceof EWAHCompressedBitmap) {
return (EWAHCompressedBitmap) r;
+ }
// Expand the bitmap but not cache the result.
XorCompressedBitmap xb = (XorCompressedBitmap) r;
@@ -100,10 +145,38 @@ abstract class BasePackBitmapIndex extends PackBitmapIndex {
int getFlags() {
return flags;
}
+
+ /**
+ * This bitmap is (currently) a base or a XOR mask
+ *
+ * @return true if this bitmap is a base (a ready map).
+ */
+ boolean isBase() {
+ return bitmapContainer instanceof EWAHCompressedBitmap;
+ }
+
+ /**
+ * Size in bytes of this bitmap in its current representation
+ *
+ * If this is a XOR'ed bitmap, size is different before/after
+ * {@link #getBitmap()}. Before is the byte size of the xor mask,
+ * afterwards is the size of the "ready" bitmap
+ *
+ * @return size in bytes of the bitmap in its current representation
+ */
+ long getCurrentSizeInBytes() {
+ Object r = bitmapContainer;
+ if (r instanceof EWAHCompressedBitmap) {
+ return ((EWAHCompressedBitmap) r).sizeInBytes();
+ }
+ XorCompressedBitmap xor = ((XorCompressedBitmap) r);
+ return xor.bitmap.sizeInBytes();
+ }
}
private static final class XorCompressedBitmap {
final EWAHCompressedBitmap bitmap;
+
final StoredBitmap xorBitmap;
XorCompressedBitmap(EWAHCompressedBitmap b, StoredBitmap xb) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
index 2334bd4851..def4f3dc11 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
@@ -196,6 +196,41 @@ public abstract class PackBitmapIndex {
public abstract int getBitmapCount();
/**
+ * Returns the number of bitmaps in this bitmap index ready to use, not
+ * XOR'ed against other entries.
+ *
+ * @return the number of bitmaps in this bitmap index ready to use.
+ */
+ public abstract int getBaseBitmapCount();
+
+ /**
+ * Current size in bytes of all base bitmaps in the index.
+ *
+ * Resolving xors for bitmaps can affect this size.
+ *
+ * @return Current size (in bytes) of all base bitmaps in this index.
+ */
+ public abstract long getBaseBitmapSizeInBytes();
+
+ /**
+ * Returns the number of bitmaps in this bitmap index XOR'ed against other
+ * entries.
+ *
+ * @return the number of bitmaps in this bitmap index represented as XOR
+ * masks.
+ */
+ public abstract int getXorBitmapCount();
+
+ /**
+ * Current size in bytes of all XOR'ed bitmaps in the index.
+ *
+ * Resolving xors for bitmaps can affect this size.
+ *
+ * @return Current size (in bytes) of all xor bitmaps in this index.
+ */
+ public abstract long getXorBitmapSizeInBytes();
+
+ /**
* Supplier that propagates IOException.
*
* @param <T>
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 91c3683501..bb7cfd0464 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
@@ -95,6 +95,26 @@ public class PackBitmapIndexRemapper extends PackBitmapIndex
}
@Override
+ public int getBaseBitmapCount() {
+ return newPackIndex.getBaseBitmapCount();
+ }
+
+ @Override
+ public long getBaseBitmapSizeInBytes() {
+ return newPackIndex.getBaseBitmapSizeInBytes();
+ }
+
+ @Override
+ public int getXorBitmapCount() {
+ return newPackIndex.getXorBitmapCount();
+ }
+
+ @Override
+ public long getXorBitmapSizeInBytes() {
+ return newPackIndex.getXorBitmapSizeInBytes();
+ }
+
+ @Override
public EWAHCompressedBitmap ofObjectType(
EWAHCompressedBitmap bitmap, int type) {
return newPackIndex.ofObjectType(bitmap, type);