go.crypto/ssh: reuse packet buffer for channel writes.

Test that different extended data streams within a channel are
thread-safe.

benchmark             old MB/s     new MB/s     speedup
BenchmarkEndToEnd     79.26        87.98        1.11x

benchmark                          old allocs     new allocs     delta
BenchmarkEndToEnd                  110            73             -33.64%

benchmark                          old bytes     new bytes     delta
BenchmarkEndToEnd                  2605720       1299768       -50.12%

LGTM=dave, jpsugar
R=agl, dave, jpsugar
CC=golang-codereviews
https://golang.org/cl/136420043
This commit is contained in:
Han-Wen Nienhuys
2014-09-16 12:30:05 -07:00
committed by Adam Langley
parent 82442e0e95
commit fc84ae5437
3 changed files with 74 additions and 7 deletions
+3 -1
View File
@@ -59,7 +59,9 @@ func (t *memTransport) writePacket(p []byte) error {
if t.write.eof {
return io.EOF
}
t.write.pending = append(t.write.pending, p)
c := make([]byte, len(p))
copy(c, p)
t.write.pending = append(t.write.pending, c)
t.write.Cond.Signal()
return nil
}