Skip to content

Perf: avoid debug-only logging work when Debug logging is disabled#787

Open
berndverst wants to merge 1 commit into
mainfrom
berndverst-perf-gate-debug-logging
Open

Perf: avoid debug-only logging work when Debug logging is disabled#787
berndverst wants to merge 1 commit into
mainfrom
berndverst-perf-gate-debug-logging

Conversation

@berndverst

Copy link
Copy Markdown
Member

Description

Fixes #770.

Avoids debug-only logging work in GrpcDurableTaskWorker.Processor when Debug logging is disabled:

  • The action-list computation (GetActionsListForLogging) for the SendingOrchestratorResponse log.
  • The UTF-8 byte-count computations for the ReceivedActivityRequest (input size) and SendingActivityResponse (output size) logs.

These computations were previously evaluated eagerly as method arguments to [LoggerMessage]-generated methods, even though the source generator itself only formats/emits the log when the level is enabled. Wrapping each call site in if (this.Logger.IsEnabled(LogLevel.Debug)) skips the extra work entirely when Debug logging is off, while producing byte-for-byte identical log content when Debug logging is on.

Scope / non-goals

  • No public API changes.
  • No behavioral changes to worker dispatch logic; traceActivity?.SetStatus(...) remains unconditional (it does not depend on Debug logging).
  • This PR is independent of any other in-flight performance PR and does not stack on or include unrelated changes.

Testing

  • Added test/Worker/Grpc.Tests/GrpcDurableTaskWorkerDebugLoggingTests.cs with targeted tests covering both the activity path and the orchestrator path:
    • Debug disabled: the byte-count/action-list logs are not emitted.
    • Debug enabled: the logs are emitted with the exact expected byte counts / action list content.
  • Ran the full test/Worker/Grpc.Tests suite (141 tests) — all passing.
  • Verified src/Worker/Grpc builds cleanly across all target frameworks.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com
Copilot-Session: c145c88d-13ab-421d-91df-184375e4ae51

Gate the debug-only action-list computation (GetActionsListForLogging)
and UTF-8 byte-count computations in
GrpcDurableTaskWorker.Processor.cs behind
this.Logger.IsEnabled(LogLevel.Debug) checks, so this work is skipped
entirely when Debug logging is disabled. When Debug logging is
enabled, log content is unchanged.

Fixes #770

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c145c88d-13ab-421d-91df-184375e4ae51
Copilot AI review requested due to automatic review settings July 24, 2026 22:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the gRPC worker’s hot-path performance by avoiding debug-only logging argument computation when Debug logging is disabled, while preserving identical debug log output when Debug is enabled.

Changes:

  • Guard Debug-level orchestrator-response logging to avoid eagerly building the actions list when Debug is off.
  • Guard Debug-level activity request/response logging to avoid UTF-8 byte counting when Debug is off.
  • Add targeted tests covering both Debug-enabled and Debug-disabled behavior for activity and orchestrator paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/Worker/Grpc.Tests/GrpcDurableTaskWorkerDebugLoggingTests.cs Adds tests validating Debug logging guards and expected log content when enabled.
src/Worker/Grpc/GrpcDurableTaskWorker.Processor.cs Wraps expensive debug-only log argument computations in Logger.IsEnabled(LogLevel.Debug) checks.

Comment on lines +339 to +342
public void Dispose()
{
}

Comment on lines +195 to +198
static GrpcDurableTaskWorker CreateActivityWorker(
GrpcDurableTaskWorkerOptions grpcOptions,
DurableTaskWorkerOptions workerOptions,
ILoggerFactory loggerFactory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance: avoid debug logging work when debug logs are disabled

2 participants