Browse Source

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
stable-3.0
Shawn Pearce 12 years ago
parent
commit
93a27ce728
  1. 14
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

14
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

@ -1147,7 +1147,9 @@ public class PackWriter {
AsyncObjectSizeQueue<ObjectToPack> sizeQueue = reader.getObjectSize(
Arrays.<ObjectToPack> 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 {

Loading…
Cancel
Save