udp
udp copied to clipboard
add put readBuffer
Description
I have make a test with pprof heap.
This result is :
(pprof) list Listen.func1
Total: 33.87GB
ROUTINE ======================== github.com/pion/udp.(*ListenConfig).Listen.func1 in /mydata/gopath/pkg/mod/github.com/pion/[email protected]/conn.go
10.77GB 10.77GB (flat, cum) 31.79% of Total
. . 132: conns: make(map[string]*Conn),
. . 133: doneCh: make(chan struct{}),
. . 134: acceptFilter: lc.AcceptFilter,
. . 135: readBufferPool: &sync.Pool{
. . 136: New: func() interface{} {
10.77GB 10.77GB 137: buf := make([]byte, receiveMTU)
. . 138: return &buf
. . 139: },
. . 140: },
. . 141: }
. . 142:
Reference issue
Then, I add put readBufferPool
// Put readBuffer
l.readBufferPool.Put(&buf)
@bjdgyc This looks cool, but I think that is not necessary to keep a buffer pool, since the buffer will live as long the listener is alive . Or we can put the getter from pool outside the for loop and put in back once the for loop is done.
What do you think @Sean-Der ?
Is there anyone ?