Most callers/users of TemporaryBuffer are sizing the in-memory portion large enough that most outputs fit into RAM. With this assumption they don't pay close attention to the size of IOs being written, as it "should" just be a copy from one byte array to another. Overflow sets up a local file handle, which is costly to write to for small IO units. Wrap the local file in a BufferedOutputStream to combine small writes together. Larger writes can still bypass the buffer as BOS automatically avoids copying for larger writes. Change-Id: I09f4136dd65c48830cfda86d9101bc647581018atags/v4.0.0.201505050340-m2
@@ -44,6 +44,7 @@ | |||
package org.eclipse.jgit.util; | |||
import java.io.BufferedOutputStream; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.FileOutputStream; | |||
@@ -435,7 +436,7 @@ public abstract class TemporaryBuffer extends OutputStream { | |||
protected OutputStream overflow() throws IOException { | |||
onDiskFile = File.createTempFile("jgit_", ".buf", directory); //$NON-NLS-1$ //$NON-NLS-2$ | |||
return new FileOutputStream(onDiskFile); | |||
return new BufferedOutputStream(new FileOutputStream(onDiskFile)); | |||
} | |||
public long length() { |