]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Clarify ownership of (*Torrent).chunkPool (#583)
authorYenForYang <YenForYang@users.noreply.github.com>
Thu, 9 Sep 2021 12:27:16 +0000 (07:27 -0500)
committerGitHub <noreply@github.com>
Thu, 9 Sep 2021 12:27:16 +0000 (22:27 +1000)
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.

peerconn.go
torrent.go

index 5d1f718b55ba97e64c11ba97ab8bd92e08a61238..fda3b95fcdb093b2b105e41776a35d13355288a7 100644 (file)
@@ -1030,7 +1030,7 @@ func (c *PeerConn) mainReadLoop() (err error) {
        decoder := pp.Decoder{
                R:         bufio.NewReaderSize(c.r, 1<<17),
                MaxLength: 256 * 1024,
-               Pool:      t.chunkPool,
+               Pool:      &t.chunkPool,
        }
        for {
                var msg pp.Message
index 70a8a9e1b7eb634cea7f8324389f4541033a8b8b..b719529f846b8ed5311da2d208a56d54a98afe6a 100644 (file)
@@ -66,7 +66,7 @@ type Torrent struct {
        // 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
@@ -233,7 +233,7 @@ func (t *Torrent) KnownSwarm() (ks []PeerInfo) {
 
 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