aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2025-06-24 10:15:17 +0300
committerIvan Frade <ifrade@google.com>2025-06-24 23:07:01 +0300
commitf52f450f9271397b0ed2581db8ccfd5b926381d6 (patch)
tree1e71b8c094ca88277159cc6f085496bfd6c91ade
parenta0baaa03b7063b21a126f03c361994b913d80f8f (diff)
downloadjgit-f52f450f9271397b0ed2581db8ccfd5b926381d6.tar.gz
jgit-f52f450f9271397b0ed2581db8ccfd5b926381d6.zip
DfsReader: Reuse index position when looking up object size
To get the indexed size of an object, we do two lookups in the primary index. First to find the object, then to find its position in the index. This hits performance when checking many object sizes on big packs. The first lookup of the object returns the index position. Reuse it for the object size index. Change-Id: If875d1b5d0b70f0cf4c448e0f9da09db65caac5e
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java28
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java8
2 files changed, 32 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
index a4bd39741d..564e607439 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
@@ -1192,7 +1192,35 @@ public final class DfsPackFile extends BlockBasedFile {
throw new IllegalArgumentException(
"Cannot get size from index since object is not in pack"); //$NON-NLS-1$
}
+ return getIndexedObjectSize(ctx, idxPosition);
+ }
+ /**
+ * Return the size of the object from the object-size index. The object
+ * should be a blob. Any other type is not indexed and returns -1.
+ * <p>
+ * Caller MUST pass a valid index position, as returned by
+ * {@link #findIdxPosition(DfsReader, AnyObjectId)} and verify the pack has
+ * object size index (e.g. with {@link #hasObjectSizeIndex(DfsReader)})
+ * before asking the indexed size.
+ *
+ * @param ctx
+ * reader context to support reading from the backing store if
+ * the object size index is not already loaded in memory.
+ * @param idxPosition
+ * position in the primary index of the object we are looking
+ * for, as returned by findIdxPosition
+ * @return size of the object from the index. Negative if object is not in
+ * the index (below threshold or not a blob)
+ * @throws IOException
+ * could not read the object size index. IO problem or the pack
+ * doesn't have it.
+ */
+ long getIndexedObjectSize(DfsReader ctx, int idxPosition)
+ throws IOException {
+ if (idxPosition < 0) {
+ throw new IllegalArgumentException("Invalid index position");
+ }
PackObjectSizeIndex sizeIdx = getObjectSizeIndex(ctx);
if (sizeIdx == null) {
throw new IllegalStateException(
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
index 568585d815..f50cd597e5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
@@ -525,7 +525,7 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs {
return last.getObjectSize(this, objectId);
}
- long sz = safeGetIndexedObjectSize(last, objectId);
+ long sz = safeGetIndexedObjectSize(last, idxPos);
if (sz >= 0) {
return sz;
}
@@ -551,7 +551,7 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs {
return last.getObjectSize(this, objectId) <= limit;
}
- long sz = safeGetIndexedObjectSize(last, objectId);
+ long sz = safeGetIndexedObjectSize(last, idxPos);
if (sz >= 0) {
return sz <= limit;
}
@@ -574,10 +574,10 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs {
}
private long safeGetIndexedObjectSize(DfsPackFile pack,
- AnyObjectId objectId) {
+ int idxPos) {
long sz;
try {
- sz = pack.getIndexedObjectSize(this, objectId);
+ sz = pack.getIndexedObjectSize(this, idxPos);
} catch (IOException e) {
// If there is any error in the index, we should have seen it
// on hasObjectSizeIndex.