mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Avoid an allocation on all requests when checking for an old user agent
ReplaceAllStrings always allocates, while scanning a relatively short regex twice is slightly more CPU immediately but less later. ``` BenchmarkGet-12 100000 108824 ns/op 17818 B/op 152 allocs/op BenchmarkGet-12 100000 108013 ns/op 17732 B/op 149 allocs/op ```
This commit is contained in:
parent
58fb665646
commit
83c41eab1d
@ -34,7 +34,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
restful "github.com/emicklei/go-restful"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -346,7 +346,10 @@ func cleanUserAgent(ua string) string {
|
||||
return "Browser"
|
||||
}
|
||||
// If an old "kubectl.exe" has passed us its full path, we discard the path portion.
|
||||
ua = kubectlExeRegexp.ReplaceAllString(ua, "$1")
|
||||
if kubectlExeRegexp.MatchString(ua) {
|
||||
// avoid an allocation
|
||||
ua = kubectlExeRegexp.ReplaceAllString(ua, "$1")
|
||||
}
|
||||
return ua
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user