How to Reduce GC Pressure in Go

Reduce Go GC pressure by minimizing heap allocations and reusing objects via sync.Pool.

Reduce GC pressure by minimizing heap allocations, avoiding unnecessary pointer indirections, and using sync.Pool for frequently allocated objects.

var pool = sync.Pool{
    New: func() interface{} {
        return &MyStruct{}
    },
}

func Get() *MyStruct {
    return pool.Get().(*MyStruct)
}

func Put(s *MyStruct) {
    pool.Put(s)
}