From fcae058a1476a793cd1623907ca5886ccd871edf Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Thu, 7 Feb 2019 13:54:13 -0800 Subject: 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 --- pkg/sentry/context/context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg/sentry/context') diff --git a/pkg/sentry/context/context.go b/pkg/sentry/context/context.go index 12bdcef85..7ed6a5e8a 100644 --- a/pkg/sentry/context/context.go +++ b/pkg/sentry/context/context.go @@ -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 } -- cgit v1.2.3