Skip to content

Commit

Permalink
eliminate mailbox delegate allocations (#6134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Oct 8, 2022
1 parent 70c57df commit 352d9a1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/core/Akka/Dispatch/Mailbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Runtime.CompilerServices;
using System.Threading;
using Akka.Actor;
using Akka.Actor.Internal;
using Akka.Configuration;
using Akka.Dispatch.MessageQueues;
using Akka.Dispatch.SysMsg;
Expand Down Expand Up @@ -147,7 +148,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));
return new LatestFirstSystemMessageList(_systemQueueDoNotCallMeDirectly);
}
}

Expand Down Expand Up @@ -271,7 +272,7 @@ private bool UpdateStatus(int oldStatus, int newStatus)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetStatus(int newStatus)
{
Volatile.Write(ref _statusDotNotCallMeDirectly, newStatus);
_statusDotNotCallMeDirectly = newStatus;
}

/// <summary>
Expand Down Expand Up @@ -371,13 +372,19 @@ public void Run()
{
try
{
if (!IsClosed()) // Volatile read, needed here
if (IsClosed()) return; // Volatile read, needed here

var tmp = InternalCurrentActorCellKeeper.Current;
InternalCurrentActorCellKeeper.Current = Actor;
try
{
ProcessAllSystemMessages(); // First, deal with any system messages
ProcessMailbox(); // Then deal with messages
}
finally
{
Actor.UseThreadContext(() =>
{
ProcessAllSystemMessages(); // First, deal with any system messages
ProcessMailbox(); // Then deal with messages
});
//ensure we set back the old context
InternalCurrentActorCellKeeper.Current = tmp;
}
}
finally
Expand Down

0 comments on commit 352d9a1

Please sign in to comment.