aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-06-26 15:17:09 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-06-26 16:13:22 -0700
commit3a7aec03e07ac853df5a00cbf06e6cd5e4ba2bc2 (patch)
tree30a238a321c3aa616ed00cb05f3ea7690fd16a25 /org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java
parentece88b99eb2ea6541b667aa066573184c25b6a8b (diff)
downloadjgit-3a7aec03e07ac853df5a00cbf06e6cd5e4ba2bc2.tar.gz
jgit-3a7aec03e07ac853df5a00cbf06e6cd5e4ba2bc2.zip
Implement zero-copy for single window objects
Objects that fall completely within a single window can be worked with in a zero-copy fashion, provided that the window is backed by a normal byte[] and not by a ByteBuffer. This works for a surprising number of objects. The default window size is 8 KiB, but most deltas are quite a bit smaller than that. Objects smaller than 1/2 of the window size have a very good chance of falling completely within a window's array, which means we can work with them without copying their data around. Larger objects, or objects which are unlucky enough to span over a window boundary, get copied through the temporary buffer. We pay a tiny penalty to realize we can't use the zero-copy code path, but its easier than trying to keep track of two adjacent windows. With this change (as well as everything preceeding it), packing is actually a bit faster. Some crude benchmarks based on cloning linux-2.6.git (~324 MiB, 1,624,785 objects) over localhost using C git client and JGit daemon shows we get better throughput, and slightly better times: Total Time | Throughput (old) (now) | (old) (now) --------------+--------------------------- 2m45s 2m37s | 12.49 MiB/s 21.17 MiB/s 2m42s 2m36s | 16.29 MiB/s 22.63 MiB/s 2m37s 2m31s | 16.07 MiB/s 21.92 MiB/s Change-Id: I48b2c8d37f08d7bf5e76c5a8020cde4a16ae3396 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java9
1 files changed, 9 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java
index 36095ed5e3..98916efcbd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java
@@ -166,6 +166,15 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
}
}
+ ByteArrayWindow quickCopy(PackFile p, long pos, long cnt)
+ throws IOException {
+ pin(p, pos);
+ if (window instanceof ByteArrayWindow
+ && window.contains(p, pos + (cnt - 1)))
+ return (ByteArrayWindow) window;
+ return null;
+ }
+
Inflater inflater() {
prepareInflater();
return inf;