libp2p / go-libp2p-circuit

Circuit Switching for libp2p
MIT License
48 stars 16 forks source link

use io.CopyBuffer with explicitly allocated buffers #69

Closed vyzo closed 5 years ago

vyzo commented 5 years ago

io.Copy uses a 32KB buffer, which as pprof indicates results in significant memory usage. This changes to using io.CopyBuffer directly with 4KB buffers.

vyzo commented 5 years ago

See https://github.com/golang/go/blob/master/src/io/io.go#L391

vyzo commented 5 years ago

Yeah, we could use a sync.Pool, steb made the same comment. Does it ever return memory? I am worried about hoarding memory when we scale up.

vyzo commented 5 years ago

reading the docs, it explicitly mentioned that pooled objects may be gc'ed which is nice.

raulk commented 5 years ago

Yeah, it holds weak references, so unused elements are elegible for collection by the GC :-)

vyzo commented 5 years ago

Added a pool.