Skip to content

perf(runtime): reduce activation collection sorting allocations - #10342

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:reubenbond-perf-freeze-well-known-types
Aug 5, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:reubenbond-perf-freeze-well-known-types

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Activation shedding snapshots and orders collection buckets by due time. Using LINQ OrderBy allocated an additional sort buffer and iterator objects on every memory-pressure collection pass.

Sort the existing snapshot array in place instead. This preserves due-time ordering and concurrency safety while avoiding the extra allocations.

In a BenchmarkDotNet comparison with 500 buckets, the in-place sort reduced mean time from 33.87 us to 27.20 us (20% faster) and allocations from 21.79 KB to 7.84 KB (64% lower).

Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings August 5, 2026 07:29

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 optimizes Orleans runtime activation shedding by removing per-collection LINQ sorting allocations when ordering activation collection buckets by due time, replacing it with an in-place sort of the existing snapshot array.

Changes:

  • Replace bucketSnapshot.OrderBy(...) with Array.Sort(...) to sort the bucket snapshot in place during memory-pressure collection.
  • Update the related concurrency/race-condition test comment to reflect the new “snapshot then sort” behavior.
Show a summary per file
File Description
src/Orleans.Runtime/Catalog/ActivationCollector.cs Sorts the bucket snapshot array in place to reduce allocations and improve activation shedding performance.
test/Orleans.Core.Tests/Runtime/ActivationCollectorTests.cs Updates test commentary to match the snapshot-and-sort approach under concurrent add/remove activity.

Copilot's findings

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

@ReubenBond
ReubenBond merged commit 4820034 into dotnet:main Aug 5, 2026
67 checks passed
@ReubenBond
ReubenBond deleted the reubenbond-perf-freeze-well-known-types branch August 5, 2026 13:04
This was referenced Aug 28, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants