Implement zero-copy for single window objects
commit3a7aec03e07ac853df5a00cbf06e6cd5e4ba2bc2
authorShawn O. Pearce <spearce@spearce.org>
Sat, 26 Jun 2010 22:17:09 +0000 (26 15:17 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 26 Jun 2010 23:13:22 +0000 (26 16:13 -0700)
tree30a238a321c3aa616ed00cb05f3ea7690fd16a25
parentece88b99eb2ea6541b667aa066573184c25b6a8b
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>
org.eclipse.jgit/src/org/eclipse/jgit/lib/ByteArrayWindow.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/PackFile.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/WindowCursor.java