Reduce multi-level buffered streams in transport code
commit2156aa894cefbabd322fc405138c306bb4e939cd
authorShawn O. Pearce <spearce@spearce.org>
Fri, 12 Feb 2010 02:10:45 +0000 (11 18:10 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 13 Mar 2010 00:08:14 +0000 (12 16:08 -0800)
treed02fd77a9510e41fd90a4aa018c1fa2016163918
parent882d03f70e089bfad2fe2e84f4f9cd69e805e332
Reduce multi-level buffered streams in transport code

Some transports actually provide stream buffering on their own,
without needing to be wrapped up inside of a BufferedInputStream in
order to smooth out system calls to read or write.  A great example
of this is the JSch SSH client, or the Apache MINA SSHD server.
Both use custom buffering to packetize the streams into the encrypted
SSH channel, and wrapping them up inside of a BufferedInputStream
or BufferedOutputStream is relatively pointless.

Our SideBandOutputStream implementation also provides some fairly
large buffering, equal to one complete side-band packet on the main
data channel.  Wrapping that inside of a BufferedOutputStream just to
smooth out small writes from PackWriter causes extra data copies, and
provides no advantage.  We can save some memory and some CPU cycles
by letting PackWriter dump directly into the SideBandOutputStream's
internal buffer array.

Instead we push the buffering streams down to be as close to the
network socket (or operating system pipe) as possible.  This allows
us to smooth out the smaller reads/writes from pkt-line messages
during advertisement and negotation, but avoid copying altogether
when the stream switches to larger writes over a side band channel.

Change-Id: I2f6f16caee64783c77d3dd1b2a41b3cc0c64c159
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/PackWriter.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java