-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filters/tracing: improve stateBagToTag #2775
filters/tracing: improve stateBagToTag #2775
Conversation
if _, ok := value.(string); ok { | ||
span.SetTag(f.tagName, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See golang/go#64541 why not
if s, ok := value.(string); ok {
span.SetTag(f.tagName, s)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we have similar cases all over the place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked all span.SetTag callsites and its fine. There may be other places that receive interface{}
like SetTag of course but I think this is a very specific pattern here - optimizing for string case.
We could simply use span.SetTag(f.tagName, value)
without type assertion but that is not guaranteed to work for types other than string, bool and ints:
// Adds a tag to the span.
//
// If there is a pre-existing tag set for `key`, it is overwritten.
//
// Tag values can be numeric types, strings, or bools. The behavior of
// other tag value types is undefined at the OpenTracing level. If a
// tracing system does not know how to handle a particular value type, it
// may ignore the tag, but shall not panic.
//
// Returns a reference to this Span for chaining.
SetTag(key string, value interface{}) Span
so I decided to keep fmt.Sprint()
Signed-off-by: Alexander Yastrebov <[email protected]>
* reduce allocations when tag value is string * check statebag value first to bail out early if it is absent * restrict max number of arguments to two ``` goos: linux goarch: amd64 pkg: github.com/zalando/skipper/filters/tracing cpu: Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz │ HEAD~1 │ HEAD │ │ sec/op │ sec/op vs base │ StateBagToTag_StringValue-8 313.1n ± 2% 124.3n ± 1% -60.29% (p=0.000 n=10) │ HEAD~1 │ HEAD │ │ B/op │ B/op vs base │ StateBagToTag_StringValue-8 19.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) │ HEAD~1 │ HEAD │ │ allocs/op │ allocs/op vs base │ StateBagToTag_StringValue-8 2.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) ``` Signed-off-by: Alexander Yastrebov <[email protected]>
8deb1eb
to
8deb30e
Compare
👍 |
1 similar comment
👍 |
Followup on #2775 Signed-off-by: Alexander Yastrebov <[email protected]>
Followup on #2775 Signed-off-by: Alexander Yastrebov <[email protected]>
For zalando-incubator/kubernetes-on-aws#6604