Skip to content

perf(runtime): lazily allocate activation request tracking#10115

Draft
ReubenBond wants to merge 1 commit into
dotnet:mainfrom
ReubenBond:rebond/lazy-activation-request-tracking
Draft

perf(runtime): lazily allocate activation request tracking#10115
ReubenBond wants to merge 1 commit into
dotnet:mainfrom
ReubenBond:rebond/lazy-activation-request-tracking

Conversation

@ReubenBond

@ReubenBond ReubenBond commented May 17, 2026

Copy link
Copy Markdown
Member

Summary

  • Lazily allocate activation waiting/running request collections instead of creating them for every activation.
  • Return empty request tracking collections for reuse.
  • Preserve null-safe inactivity and request-count semantics for activations with no queued or running requests.

Validation

  • dotnet build src\Orleans.Runtime\Orleans.Runtime.csproj --nologo --verbosity minimal -property:UseSharedCompilation=false
  • dotnet build test\Grains\TestVersionGrains\TestVersionGrains.csproj --nologo --verbosity minimal -property:UseSharedCompilation=false
  • dotnet build test\Grains\TestVersionGrains2\TestVersionGrains2.csproj --nologo --verbosity minimal -property:UseSharedCompilation=false
  • dotnet test test\Orleans.Runtime.Tests\Orleans.Runtime.Tests.csproj --no-build --nologo --verbosity minimal -property:UseSharedCompilation=false
Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 reduces per-activation allocations in the Orleans runtime by lazily creating (and reusing) the collections used to track queued and running requests for an activation, while keeping existing “no requests” semantics intact.

Changes:

  • Lazily allocate _waitingRequests and _runningRequests in ActivationData and update related logic to be null-safe.
  • Introduce shared pools for the request-tracking collections and return them for reuse when they become empty.
Show a summary per file
File Description
src/Orleans.Runtime/Catalog/GrainTypeSharedContext.cs Adds shared pools plus rent/return helpers for request-tracking collections.
src/Orleans.Runtime/Catalog/ActivationData.cs Switches request tracking to lazy allocation, adds return-to-pool logic, and updates null-safe request-count/inactivity checks.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment on lines +24 to +25
private static readonly ConcurrentStack<Dictionary<Message, CoarseStopwatch>> RunningRequestsMapPool = new();
private static readonly ConcurrentStack<List<(Message Message, CoarseStopwatch QueuedTime)>> WaitingRequestsListPool = new();
@ReubenBond ReubenBond changed the title Lazily allocate activation request tracking perf(runtime): lazily allocate activation request tracking May 29, 2026
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.

2 participants