Open CaojiamingAlan opened 1 year ago
@pavelkalinnikov Thank you for your comments! I've resolved them.
we still reallocate and copy the slice.
The trick is at when we put back the slice:
rn.raft.msgsAfterAppendPool.Put(rn.raft.msgsAfterAppend[:0])
This clears the slice but reserves the underlying array, which we can reuse so that we don't need to allocate a new one each iteration.
Solve https://github.com/etcd-io/raft/issues/15: Use pooled slice to reduce the total bytes allocated. Benchmark result: