summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2019-02-07 13:54:13 -0800
committerShentubot <shentubot@google.com>2019-02-07 13:55:23 -0800
commitfcae058a1476a793cd1623907ca5886ccd871edf (patch)
tree7ab67e823b45c9b7d40cb34eea3916ff20f01b60
parente0afa8789963c18c1afed7d222754ef4b7415a7d (diff)
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
-rw-r--r--pkg/sentry/context/context.go5
1 files changed, 4 insertions, 1 deletions
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
}