net/http: avoid copy if WithContext attempts to set exact same *ctx object #44525
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
Prior to
NewRequestWithContext
a lot of code looked like:Now that
NewRequestWithContext
is a thing, existing code may get ported - incorrectly - as:Under the hood,
WithContext
does this:Basically, my suggestion is to check if the incoming
ctx
and the existingr.ctx
point to the same value in memory, then avoid the copy tor2
and just returnr
in that case.In theory this is a breaking change of behavior if someone is doing e.g.
and then using both
req
andreq2
though I don't think the behavior is very well defined if you do that.The text was updated successfully, but these errors were encountered: