From eb2033e982e5190785ab75a388b8383fd0cedbd5 Mon Sep 17 00:00:00 2001 From: Bin Wu <46450037+wu-bin@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:42:53 -0500 Subject: [PATCH] Make ScopedExecutionContext no-op if !ExecutionContext::isEnabled(). (#37069) Make `ScopedExecutionContext` no-op if `!ExecutionContext::isEnabled()`. This saves a call to `ScopeTrackedObject::trackedStream()` when execution context is disabled. Commit Message: Make ScopedExecutionContext no-op if !ExecutionContext::isEnabled(). Additional Description: Risk Level: None. Testing: Existing execution_context_test.cc. Docs Changes: N/A Release Notes: N/A Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: Bin Wu --- envoy/common/execution_context.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/envoy/common/execution_context.h b/envoy/common/execution_context.h index 3580f8f2bd3b..dada24e31697 100644 --- a/envoy/common/execution_context.h +++ b/envoy/common/execution_context.h @@ -81,8 +81,9 @@ class ScopedExecutionContext : NonCopyable { public: ScopedExecutionContext() : ScopedExecutionContext(nullptr) {} ScopedExecutionContext(const ScopeTrackedObject* object) - : context_(object != nullptr ? ExecutionContext::fromStreamInfo(object->trackedStream()) - : nullptr) { + : context_((object != nullptr && ExecutionContext::isEnabled()) + ? ExecutionContext::fromStreamInfo(object->trackedStream()) + : nullptr) { if (context_ != nullptr) { context_->activate(); }