Skip to content

Commit

Permalink
Reduced allocations around ActorCell and Task handling (#5053)
Browse files Browse the repository at this point in the history
* Made `ActorCell.SendSystemMessage` `virtual` so it can be subclassed
* Made a number of `ActorCell` methods `static` to reduce object memory footprint
* Reduced number of possible `Task` allocations where they weren't needed
  • Loading branch information
Aaronontheweb authored Jun 3, 2021
1 parent 2715c36 commit 15492d0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace Akka.Actor
public void Resume(System.Exception causedByFailure) { }
public virtual void SendMessage(Akka.Actor.Envelope message) { }
public virtual void SendMessage(Akka.Actor.IActorRef sender, object message) { }
public void SendSystemMessage(Akka.Dispatch.SysMsg.ISystemMessage systemMessage) { }
public virtual void SendSystemMessage(Akka.Dispatch.SysMsg.ISystemMessage systemMessage) { }
protected void SetActorFields(Akka.Actor.ActorBase actor) { }
protected bool SetChildrenTerminationReason(Akka.Actor.Internal.SuspendReason reason) { }
public void SetReceiveTimeout(System.Nullable<System.TimeSpan> timeout = null) { }
Expand Down
10 changes: 5 additions & 5 deletions src/core/Akka/Actor/ActorCell.DefaultMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private void Supervise(IActorRef child, bool async)
}
}

private void HandleSupervise(IActorRef child, bool async)
private static void HandleSupervise(IActorRef child, bool async)
{
if (async && child is RepointableActorRef @ref)
{
Expand Down Expand Up @@ -506,11 +506,11 @@ public void Suspend()
}

/// <summary>
/// TBD
/// Handles a <see cref="ISystemMessage"/>
/// </summary>
/// <remarks>➡➡➡ NEVER SEND THE SAME SYSTEM MESSAGE OBJECT TO TWO ACTORS ⬅⬅⬅</remarks>
/// <param name="systemMessage">TBD</param>
public void SendSystemMessage(ISystemMessage systemMessage)
/// <param name="systemMessage">The system message to process.</param>
public virtual void SendSystemMessage(ISystemMessage systemMessage)
{
try
{
Expand All @@ -522,7 +522,7 @@ public void SendSystemMessage(ISystemMessage systemMessage)
}
}

private void Kill()
private static void Kill()
{
throw new ActorKilledException("Kill");
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ReceiveActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private PartialAction<object> CreateNewHandler(Action configure)
return newHandler;
}

private Action<T> WrapAsyncHandler<T>(Func<T, Task> asyncHandler)
private static Action<T> WrapAsyncHandler<T>(Func<T, Task> asyncHandler)
{
return m =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Dispatch/ActorTaskScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void RunTask(Action action)
RunTask(() =>
{
action();
return Task.FromResult(0);
return Task.CompletedTask;
});
}

Expand Down

0 comments on commit 15492d0

Please sign in to comment.