You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the value isn't comparable then there would be no way to retrieve it.
Ensuring that the program runs correctly should be more important.
See the change that added it: https://go-review.googlesource.com/c/go/+/21799/
context.Context is an interface and people are free to create other implementations with less safety.
What version of Go are you using (
go version
)?What did you do?
When I use
context.WithValue()
, I see it always cost20ns/op +
I checked the source codes, i found a
TypeOf(key).Comparable()
https://github.com/golang/go/blob/master/src/context/context.go#L530,Then i remove it,
WithValue
become fastersee the Benchmark results below
Maybe we could consider to remove https://github.com/golang/go/blob/master/src/context/context.go#L530
Or just make valuectx public for people to recreate a faster
WithValue
The text was updated successfully, but these errors were encountered: