4 ms·
If you have a long-lived functionality in your Go program that needs buffers, it may just be best to allocate a pool of buffers and reuse them. Go does offer a
by brian-armstrong 10y ago
If you have a long-lived functionality in your Go program that needs buffers, it may just be best to allocate a pool of buffers and reuse them. Go does offer a basic primitive for this with sync.Pool
I once wrote a high throughput UDP listener that maxed out all the cores to deal with receiving some bursty UDP traffic. I realized that interacting with the memory allocater was my bottleneck, so I just moved to a pool of UDP buffers. My ability to deal with load spikes improved substantially. There's no reason not to use Pools in general if you're building a service with a predictable and repeatable object lifetime