Skip to content

Large memory allocation on pools.Put #7

@ehsannm

Description

@ehsannm

Hi,

I was benchmarking my lib which is using of gobwas/pbytes package extensively, however, during my benchamrks i found
that there is a large amount of allocation happens in pool.Put() function. I checked i didn't find anything. That is why i have asking it here maybe you could help me to find out.

github.com/gobwas/pool/pbytes.(*Pool).Put
/Users/ehsan/Dev/ronak/go/rony/vendor/github.com/gobwas/pool/pbytes/pool.go

  Total:    237.51MB   237.51MB (flat, cum) 92.18%
     42            .          .            
     43            .          .           // Put returns given slice to reuse pool. 
     44            .          .           // It does not reuse bytes whose size is not power of two or is out of pool 
     45            .          .           // min/max range. 
     46            .          .           func (p *Pool) Put(bts []byte) { 
     47     237.51MB   237.51MB           	p.pool.Put(bts, cap(bts)) 
     48            .          .           } 
     49            .          .            
     50            .          .           // GetCap returns probably reused slice of bytes with at least capacity of n. 
     51            .          .           func (p *Pool) GetCap(c int) []byte { 
     52            .          .           	return p.Get(0, c) 
github.com/gobwas/pool/pbytes.(*Pool).Get
/Users/ehsan/Dev/ronak/go/rony/vendor/github.com/gobwas/pool/pbytes/pool.go

  Total:      9.50MB     9.50MB (flat, cum)  3.69%
     35            .          .           		bts := v.([]byte) 
     36            .          .           		bts = bts[:n] 
     37            .          .           		return bts 
     38            .          .           	} 
     39            .          .            
     40       9.50MB     9.50MB           	return make([]byte, n, x) 
     41            .          .           } 
     42            .          .            
     43            .          .           // Put returns given slice to reuse pool. 
     44            .          .           // It does not reuse bytes whose size is not power of two or is out of pool 
     45            .          .           // min/max range. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions