-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
log: Unexport Context #481
Conversation
At first glace the benchmark changes look like a regression, but after investigating the increase in allocations I have determined that the benchmarks on master are flawed. The flaw is explained in the comments below. func BenchmarkOneWith(b *testing.B) {
logger := log.NewNopLogger()
// The old code returned a concrete *log.Context to lc.
// lc := log.NewContext(logger).With("k", "v")
// The new code returns a log.Logger interface value to lc.
// That prevents escape analysis from eliminating the allocation
// of the keyvals slice passed to Log.
// I think most client code will be using variables of type
// log.Logger to hold the context, so the old benchmark
// was measuring an atypical use case.
lc := log.With(logger, "k", "v")
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
lc.Log("k", "v")
}
} |
This update also contains a few other minor documentation updates.
Interesting. I'd like to understand this better. How did you know escape analysis was the culprit? Why is the slice allocated for Log on an interface instead of Log on a struct? |
I inferred that from a couple pieces of information.
|
This looks good to me. I'm happy to take the breaking change. |
@peterbourgon What do you think of my revised language in the documentation in doc.go and log.go? |
Yes, it's great. I like that the previously floating comment about stack frame details now has a home on the unexported context type. |
OK. Merging. |
log: Unexport Context
Implement #474.
The first commit makes the API change in the simplest way possible and patches dependent packages within this repository to account for the change.
Work remaining: