-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eliminate mailbox delegate allocations #6134
eliminate mailbox delegate allocations #6134
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed my own PR
@@ -142,7 +143,7 @@ internal LatestFirstSystemMessageList SystemQueue | |||
{ | |||
// Note: contrary how it looks, there is no allocation here, as SystemMessageList is a value class and as such | |||
// it just exists as a typed view during compile-time. The actual return type is still SystemMessage. | |||
return new LatestFirstSystemMessageList(Volatile.Read(ref _systemQueueDoNotCallMeDirectly)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed - field is already marked as volatile
@@ -201,7 +202,7 @@ public virtual void SetActor(ActorCell actorCell) | |||
/// TBD | |||
/// </summary> | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
internal int CurrentStatus() { return Volatile.Read(ref _statusDotNotCallMeDirectly); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed - field is already marked as volatile
@@ -251,7 +252,7 @@ private bool UpdateStatus(int oldStatus, int newStatus) | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
private void SetStatus(int newStatus) | |||
{ | |||
Volatile.Write(ref _statusDotNotCallMeDirectly, newStatus); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed - field is already marked as volatile
if (!IsClosed()) // Volatile read, needed here | ||
if (IsClosed()) return; // Volatile read, needed here | ||
|
||
var tmp = InternalCurrentActorCellKeeper.Current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined the contents of ActorCell.UseThreadContext
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Changes
Reduces delegate allocations while processing actor mailbox contents to zero - eliminates the vast majority of allocations that occur during mailbox processing.
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):
Latest
v1.4
BenchmarksRunning on .NET 6 - note: I modified the
MailboxThroughputBenchmarks
to only use theCallingThreadDispatcher
as that's a cleaner signal for measuring throughput impact of these changes, which otherwise won't show up as easily using the .NET ThreadPool.This PR's Benchmarks
Perf Summary
Reduces allocations on 100,000 msgs processed from 203kb to 1,008 bytes. Improves throughput slightly.