From 53ad30a268251846a6e3e384b519ba0226cefa19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Tue, 4 Aug 2026 03:45:17 +0200 Subject: [PATCH] plugin/kubernetes: pre-allocate search path slice capacity in AutoPath (#8381) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: add benchmark cases for Request IP/Port and parseRequest Signed-off-by: Manuel Rüger * perf(kubernetes): optimize AutoPath slice allocation and copy Signed-off-by: Manuel Rüger * perf(kubernetes): pre-allocate search path slice capacity in AutoPath Signed-off-by: Manuel Rüger --------- Signed-off-by: Manuel Rüger --- plugin/kubernetes/autopath.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugin/kubernetes/autopath.go b/plugin/kubernetes/autopath.go index f20f03c7c..af6502c7f 100644 --- a/plugin/kubernetes/autopath.go +++ b/plugin/kubernetes/autopath.go @@ -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 }