plugin/kubernetes: pre-allocate search path slice capacity in AutoPath (#8381)

* test: add benchmark cases for Request IP/Port and parseRequest

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

* perf(kubernetes): optimize AutoPath slice allocation and copy

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

* perf(kubernetes): pre-allocate search path slice capacity in AutoPath

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

---------

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
Manuel Rüger
2026-08-04 03:45:17 +02:00
committed by GitHub
parent a1642a64dc
commit 53ad30a268

View File

@@ -33,16 +33,21 @@ func (k *Kubernetes) AutoPath(state request.Request) []string {
return nil
}
totalSize := 3 + len(k.autoPathSearch) + 1 // +1 for sentinel
search := make([]string, 0, totalSize)
totalSize := 4 + len(k.autoPathSearch)
search := make([]string, totalSize)
if zone == "." {
search = append(search, pod.Namespace+".svc.", "svc.", ".")
search[0] = pod.Namespace + ".svc."
search[1] = "svc."
search[2] = "."
} else {
search = append(search, pod.Namespace+".svc."+zone, "svc."+zone, zone)
svcZone := "svc." + zone
search[0] = pod.Namespace + "." + svcZone
search[1] = svcZone
search[2] = zone
}
search = append(search, k.autoPathSearch...)
search = append(search, "") // sentinel
copy(search[3:], k.autoPathSearch)
search[totalSize-1] = "" // sentinel
return search
}