Make context.Background return a global background context.
It currently allocates a new context on the heap each time it is called. Some of these are in relatively hot paths like signal delivery and releasing gofer inodes. It is also called very commonly in afterLoad. All of these should benefit from fewer heap allocations. PiperOrigin-RevId: 232938873 Change-Id: I53cec0ca299f56dcd4866b0b4fd2ec4938526849
This commit is contained in:
parent
e0afa87899
commit
fcae058a14
|
@ -108,6 +108,9 @@ func (NoopSleeper) UninterruptibleSleepStart(bool) {}
|
|||
// UninterruptibleSleepFinish does nothing.
|
||||
func (NoopSleeper) UninterruptibleSleepFinish(bool) {}
|
||||
|
||||
// bgContext is the context returned by context.Background.
|
||||
var bgContext = &logContext{Logger: log.Log()}
|
||||
|
||||
// Background returns an empty context using the default logger.
|
||||
//
|
||||
// Users should be wary of using a Background context. Please tag any use with
|
||||
|
@ -119,5 +122,5 @@ func (NoopSleeper) UninterruptibleSleepFinish(bool) {}
|
|||
// Using a Background context for tests is fine, as long as no values are
|
||||
// needed from the context in the tested code paths.
|
||||
func Background() Context {
|
||||
return logContext{Logger: log.Log()}
|
||||
return bgContext
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue