Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
context: Remove allocation discussion from WithValue documentation #33742
This is a proposed package documentation change. I'm happy to submit a code change with this update, if it makes sense. I took the liberty of abbreviating the questions in the template.
What version of Go are you using (
If you change
then it allocates. If you change
then it allocates. (Tested with Go 1.12.5.)
There are some nice optimizations to prevent certain interface allocations, but they shouldn't be documented here. Best to stick with simple rules of thumb.
Wow thanks @cespare! Since I was wrong and this does matter, should we change the example in the package to follow its own advice and not use
There is also duplicated description about context key types: There is a description on Context.Value: "A key can be any type that supports equality [...]", as well as on
Here are the updated metrics with the var string and key types for Go 1.12. As you can see: var/const makes a huge difference.