From 93a27ce7287c5574bcf1ed872e8964314fc8818b Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Thu, 4 Apr 2013 11:23:16 -0700 Subject: [PATCH] Simplify size test in PackWriter Clip the configured limit to Integer.MAX_VALUE at the top of the loop, saving a compare branch per object considered. This can cut 2M branches out of a repacking of the Linux kernel. Rewrite the logic so the primary path is to match the conditional; most objects are larger than BLKSZ (16 bytes) and less than limit. This may help branch prediction on CPUs if the CPU tries to assume execution takes the side of the branch and not the second. Change-Id: I5133d1651640939afe9fbcfd8cfdb59965c57d5a --- .../jgit/internal/storage/pack/PackWriter.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index cd8f462b2..7da2cd5d0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -1147,7 +1147,9 @@ public class PackWriter { AsyncObjectSizeQueue sizeQueue = reader.getObjectSize( Arrays. asList(list).subList(0, cnt), false); try { - final long limit = config.getBigFileThreshold(); + final long limit = Math.min( + config.getBigFileThreshold(), + Integer.MAX_VALUE); for (;;) { try { if (!sizeQueue.next()) @@ -1175,14 +1177,10 @@ public class PackWriter { otp = objectsMap.get(sizeQueue.getObjectId()); long sz = sizeQueue.getSize(); - if (limit <= sz || Integer.MAX_VALUE <= sz) - otp.setDoNotDelta(); // too big, avoid costly files - - else if (sz <= DeltaIndex.BLKSZ) - otp.setDoNotDelta(); // too small, won't work - - else + if (DeltaIndex.BLKSZ < sz && sz < limit) otp.setWeight((int) sz); + else + otp.setDoNotDelta(); // too small, or too big monitor.update(1); } } finally {