Skip to content

perf(runtime): reduce callback tracking contention#10062

Draft
ReubenBond wants to merge 1 commit into
dotnet:mainfrom
ReubenBond:split/striped-callback-dictionary
Draft

perf(runtime): reduce callback tracking contention#10062
ReubenBond wants to merge 1 commit into
dotnet:mainfrom
ReubenBond:split/striped-callback-dictionary

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Apr 30, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds StripedCallbackDictionary for callback tracking.
  • Updates callback ID/hash generation and inside/outside runtime clients to use the striped dictionary.

Validation

  • git diff --check
  • conflict-marker scan
  • dotnet build src\Orleans.Core\Orleans.Core.csproj -m

Notes

  • No dedicated concurrency tests were added. Follow-up coverage should include concurrent add/remove/lookup, response lookup under high concurrency, stripe mismatch behavior, and reconnect/retry interactions.
Microsoft Reviewers: Open in CodeFlow

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 contention in callback tracking by replacing the existing callback dictionaries with a striped implementation and by embedding a stripe selector into CorrelationId values generated for outgoing requests.

Changes:

  • Introduce StripedCallbackDictionary<TValue> for callback tracking with per-stripe locking.
  • Update inside/outside runtime clients to use the striped dictionary keyed by CorrelationId.
  • Update correlation id generation to encode stripe bits into the upper bits of the id (and adjust CorrelationId.GetHashCode()).
Show a summary per file
File Description
src/Orleans.Runtime/Core/InsideRuntimeClient.cs Switch callback tracking to StripedCallbackDictionary and simplify keying/removal to CorrelationId.
src/Orleans.Core/Runtime/OutsideRuntimeClient.cs Switch client-side callback tracking to StripedCallbackDictionary and update request counting.
src/Orleans.Core/Messaging/StripedCallbackDictionary.cs Add new striped dictionary implementation (per-stripe lock + snapshot enumeration).
src/Orleans.Core/Messaging/MessageFactory.cs Encode stripe index into generated CorrelationId values.
src/Orleans.Core/Messaging/CorrelationId.cs Update hash code implementation for CorrelationId.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 3

Comment on lines 26 to 30
private readonly ILogger logger;
private readonly ClientMessagingOptions clientMessagingOptions;

private readonly ConcurrentDictionary<CorrelationId, CallbackData> callbacks;
private readonly StripedCallbackDictionary<CallbackData> callbacks;
private InvokableObjectManager localObjects;
Comment on lines +155 to +165
lock (stripe.Lock)
{
foreach (var kvp in stripe.Dictionary)
{
if (predicate(kvp))
{
count++;
}
}
}
}
Comment on lines 50 to 55
private CorrelationId GetNextCorrelationId()
{
var id = _seed ^ Interlocked.Increment(ref _nextId);
return new CorrelationId(unchecked((long)id));
var stripeIndex = StripedCallbackDictionary<object>.GetCurrentThreadStripeIndex();
return StripedCallbackDictionary<object>.CreateCorrelationId(unchecked((long)id), stripeIndex);
}
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ReubenBond ReubenBond force-pushed the split/striped-callback-dictionary branch from fcbac7d to 1efc300 Compare April 30, 2026 15:34
@ReubenBond ReubenBond changed the title Reduce callback tracking contention with striped callback dictionary perf(runtime): reduce callback tracking contention 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