context: cancelCtx should avoid to use map to store child cancelers #47806
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Currently,
cancelCtx
uses map to store all child contextsgo/src/context/context.go
Lines 265 to 275 in c85695a
But it causes map allocation and may be ineffective if there is only one child context. This case is quite common, at least in my projects.
I made a simple patch which stores first child in separate field (tdakkota@1c4f3b2) and see an improvement.
Benchmark result:
Any thoughts?
The text was updated successfully, but these errors were encountered: