net/http: Avoid copying URL in Request.WithContext #52239
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
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?
A common pattern in HTTP middleware is to compute a value, derive a new context with
Context.WithValue
(orWithDeadline
, etc), attach the context to the request usingWithContext
, and invoke thenext
handler (https://goji.io/ in particular encourages this pattern for middleware, but I think it is generally common).WithContext
has a TODO around trying to remove the not-quite-deep-but-not-quite-shallow behavior of copying the URL now that additionalNewRequestWithContext
andClone
methods exist for http.Requests:I'd like to remove this copy, as users now have
Clone
to get real deep-copy semantics.What did you expect to see?
One less allocation in this common hot-path function.
What did you see instead?
An allocation for legacy behavior with a TODO to remove it.
The text was updated successfully, but these errors were encountered: