Optimize orchestration history scans for tracing performance - #799
Open
Chris Sheldrick (csheldrick) wants to merge 2 commits into
Open
Optimize orchestration history scans for tracing performance#799Chris Sheldrick (csheldrick) wants to merge 2 commits into
Chris Sheldrick (csheldrick) wants to merge 2 commits into
Conversation
perf: avoid repeated orchestration history scans for tracing
Copilot started reviewing on behalf of
Chris Sheldrick (csheldrick)
September 1, 2026 04:39
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the gRPC worker’s orchestration tracing path by avoiding repeated scans of orchestration history and skipping all tracing lookup/indexing work when the Durable Task ActivitySource has no listeners. It introduces a one-pass index over relevant past history events to enable O(1) lookups for completed/failed task and sub-orchestration tracing, while preserving prior “first/last match” semantics.
Changes:
- Add a listener gate (
TraceHelper.HasListeners()) so history lookup/indexing work is skipped when tracing is inactive. - Introduce
TracingHistoryEventIndexto build a single-pass index over relevantPastEventsand use it duringNewEventsprocessing. - Add unit tests covering duplicate IDs, missing IDs, and listener detection behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/Grpc/Tracing/TraceHelper.cs | Adds a listener-detection helper used to skip tracing work when no listeners exist. |
| src/Worker/Grpc/GrpcDurableTaskWorker.Processor.cs | Uses the listener gate and the new history index to avoid repeated history scans during tracing. |
| src/Worker/Grpc/TracingHistoryEventIndex.cs | New helper to index past history events for O(1) tracing lookups while preserving first/last semantics. |
| test/Worker/Grpc.Tests/TraceHelperTests.cs | Adds unit test for listener detection behavior. |
| test/Worker/Grpc.Tests/TracingHistoryEventIndexTests.cs | Adds unit tests validating duplicate-ID and missing-ID lookup semantics. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+15
to
+18
| ActivityListener listener = new() | ||
| { | ||
| ShouldListenTo = source => source.Name == "Microsoft.DurableTask", | ||
| }; |
Comment on lines
+23
to
+29
| // Preserve the previous FirstOrDefault semantics for duplicate IDs. | ||
| if (!this.subOrchestrationCreatedEvents.ContainsKey(historyEvent.EventId)) | ||
| { | ||
| this.subOrchestrationCreatedEvents.Add(historyEvent.EventId, historyEvent); | ||
| } | ||
|
|
||
| break; |
Comment on lines
+23
to
+27
| /// <summary> | ||
| /// Gets whether any listener is subscribed to Durable Task tracing activities. | ||
| /// </summary> | ||
| /// <returns><see langword="true"/> when tracing work can produce activities; otherwise, <see langword="false"/>.</returns> | ||
| public static bool HasListeners() => ActivityTraceSource.HasListeners(); |
Author
|
@microsoft-github-policy-service agree [company="csheldrick"] |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What changed?
Why is this change needed?
Issues / work items
⸻
Project checklist
⸻
AI-assisted code disclosure (required)
Was an AI tool used? (select one)
If AI was used:
AI verification (required if AI was used):
⸻
Testing
Automated tests
Manual validation (only if runtime/behavior changed)
⸻
Notes for reviewers