each iteration copies 1112 bytes (consider pointers or indexing)
366 }
367
368 podsReady := 0
369 for _, pod := range actualPods {370 if isPodReady(pod) {
371 podsReady++
372 }
each iteration copies 600 bytes (consider pointers or indexing)
338
339func getNotRunningPodLogs() {
340 events, _ := kubeClient.CoreV1().Events(namespace).List(context.TODO(), metav1.ListOptions{FieldSelector: "status.phase!=Running", TypeMeta: metav1.TypeMeta{Kind: "Pod"}})
341 for _, item := range events.Items {342 fmt.Println(item)
343 }
344}
Description
Avoid for
loop range expressions that copy big objects for each iteration.
It is recommended to use index-based access or use pointers instead.
Bad practice
xs := make([][1024]byte, length)
for _, x := range xs {
// Loop body.
}
Recommended
xs := make([][1024]byte, length)
for i := range xs {
x := &xs[i]
// Loop body.
}