Pre-allocate capacity when you know the size:
// Bad: many reallocations
var nums []int
for i := 0; i < 10000; i++ {
nums = append(nums, i)
}
// Good: single allocation
nums := make([]int, 0, 10000)
for i := 0; i < 10000; i++ {
nums = append(nums, i)
}
Pre-allocation avoids repeated copying as the slice grows.