udp icon indicating copy to clipboard operation
udp copied to clipboard

add put readBuffer

Open bjdgyc opened this issue 4 years ago • 2 comments

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 avatar Jun 01 '21 09:06 bjdgyc

@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 ?

OrlandoCo avatar Jun 04 '21 02:06 OrlandoCo

Is there anyone ?

bjdgyc avatar Jul 19 '21 08:07 bjdgyc