mirror of
https://github.com/coredns/coredns.git
synced 2026-08-20 23:08:28 -04:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user