The Impact of Pre-allocating Slice Memory on Performance in Golang
https://oilbeater.com/en/2024/03/04/golang-slice-performance
During my code reviews, I often focus on whether the slice initialization in the code has allocated the expected memory space, that is, I always request to change from var init []int64 to init := make([]int64, 0, length) format whenever possible. However, I had no quantitative concept of how much this improvement affects performance, and it was more of a dogmatic requirement. This blog will introduce the theoretical basis of how pre-allocating memory improves performance, quantitative measurements, and tools for automated detection.
https://oilbeater.com/en/2024/03/04/golang-slice-performance