netpoll
netpoll copied to clipboard
feat: Added Reuse and Initialize methods to LinkBuffer
When used with sharequeue, the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.
the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.
@Nana-Miko Hi, can you show me your code and how it cause GC pressure?
the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.
@Nana-Miko Hi, can you show me your code and how it cause GC pressure?
sure!
queue := mux.NewShardQueue(mux.ShardSize, conn)
// Simulating pressure environment using for loops
for {
var getter mux.WriterGetter = func() (buf Writer, isNil bool) {
// I can't use sync.Pool to get buf
// In this func,'var buf = &LinkBuffer{}' will continuously allocate memory
buf = NewLinkBuffer(128)
buf.Malloc(128)
buf.Flush()
return buf, false
}
queue.Add(getter)
}
In this example, is there any way to reuse LinkBuffer using sync.Pool?