mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Use io.CopyBuffer in websocketconn.readLoop.
This avoids io.Copy allocating a 32 KB buffer on every call. https://cs.opensource.google/go/go/+/refs/tags/go1.19.1:src/io/io.go;l=416 $ go test -bench=BenchmarkReadWrite -benchmem -benchtime=5s BenchmarkReadWrite/c←s_150-4 385740 15114 ns/op 9.92 MB/s 4104 B/op 3 allocs/op BenchmarkReadWrite/s←c_150-4 347070 16824 ns/op 8.92 MB/s 4152 B/op 4 allocs/op BenchmarkReadWrite/c←s_3000-4 190257 31581 ns/op 94.99 MB/s 8208 B/op 6 allocs/op BenchmarkReadWrite/s←c_3000-4 163233 34821 ns/op 86.16 MB/s 8304 B/op 8 allocs/op
This commit is contained in:
parent
3df514ae29
commit
264425a488
1 changed files with 2 additions and 1 deletions
|
@ -50,7 +50,8 @@ func readLoop(w io.Writer, ws *websocket.Conn) error {
|
|||
if messageType != websocket.BinaryMessage && messageType != websocket.TextMessage {
|
||||
continue
|
||||
}
|
||||
_, err = io.Copy(w, r)
|
||||
var buf [2048]byte
|
||||
_, err = io.CopyBuffer(w, r, buf[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue