Boxing In Hot Path (ARCH5087)
Esta página aún no está disponible en tu idioma.
Key go.performance.boxing-in-hot-path · Severity info · Category performance
Wrapping values in interface{} (any) inside a tight loop forces a heap allocation on every iteration. Keep concrete types on hot paths.
Incorrect
Section titled “Incorrect”func sum(nums []int) int { var total int for _, n := range nums { var boxed any = n total += boxed.(int) } return total}Correct
Section titled “Correct”func sum(nums []int) int { var total int for _, n := range nums { total += n } return total}Remove interface{}/any wrapping in hot loops and use the concrete type directly.