Basically bind the lifetime of chunkPool to the torrent by using `sync.Pool` in lieu of `*sync.Pool`. Gives the GC ever so slightly less work to do.
decoder := pp.Decoder{
R: bufio.NewReaderSize(c.r, 1<<17),
MaxLength: 256 * 1024,
- Pool: t.chunkPool,
+ Pool: &t.chunkPool,
}
for {
var msg pp.Message
// The size of chunks to request from peers over the wire. This is
// normally 16KiB by convention these days.
chunkSize pp.Integer
- chunkPool *sync.Pool
+ chunkPool sync.Pool
// Total length of the torrent in bytes. Stored because it's not O(1) to
// get this from the info dict.
length *int64
func (t *Torrent) setChunkSize(size pp.Integer) {
t.chunkSize = size
- t.chunkPool = &sync.Pool{
+ t.chunkPool = sync.Pool{
New: func() interface{} {
b := make([]byte, size)
return &b