Skip to content

Commit

Permalink
improveme child lookup performance (#5241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb authored Sep 2, 2021
1 parent f0c0ebf commit 4c494fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/benchmark/Akka.Benchmarks/Actor/GetChildBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected override void OnReceive(object message)
private ActorWithChild.Get _getMessage = new ActorWithChild.Get("food");
private ActorWithChild.Create _createMessage = new ActorWithChild.Create("food");

private ActorCell _cell;
private IActorContext _cell;
private RepointableActorRef _repointableActorRef;
private LocalActorRef _localActorRef;
private VirtualPathContainer _virtualPathContainer;
Expand Down Expand Up @@ -129,7 +129,7 @@ public async Task Setup()
[Benchmark]
public void ResolveChild()
{
_cell.TryGetSingleChild(_getMessage.Name, out var child);
_cell.Child(_getMessage.Name);
}

[Benchmark]
Expand Down
8 changes: 4 additions & 4 deletions src/core/Akka/Actor/ActorCell.Children.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ protected void SetTerminated()
{
get
{
var terminating = ChildrenContainer as TerminatingChildrenContainer;
return terminating != null && terminating.Reason is SuspendReason.IWaitingForChildren;
return ChildrenContainer is TerminatingChildrenContainer terminating && terminating.Reason is SuspendReason.IWaitingForChildren;
}
}

Expand Down Expand Up @@ -325,8 +324,7 @@ public bool TryGetChildStatsByName(string name, out IChildStats child) //This
/// </summary>
private bool TryGetChildRestartStatsByName(string name, out ChildRestartStats child)
{
IChildStats stats;
if (ChildrenContainer.TryGetByName(name, out stats))
if (ChildrenContainer.TryGetByName(name, out var stats))
{
child = stats as ChildRestartStats;
if (child != null)
Expand Down Expand Up @@ -362,6 +360,8 @@ public IInternalActorRef GetSingleChild(string name)
return TryGetSingleChild(name, out child) ? child : ActorRefs.Nobody;
}



/// <summary>
/// TBD
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion src/core/Akka/Actor/ActorCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ public void Init(bool sendSupervise, MailboxType mailboxType)

IActorRef IActorContext.Child(string name)
{
return TryGetSingleChild(name, out var child) ? child : ActorRefs.Nobody;
if (TryGetChildStatsByName(name, out var child) && child is ChildRestartStats s)
return s.Child;

return ActorRefs.Nobody;
}

/// <summary>
Expand Down

0 comments on commit 4c494fe

Please sign in to comment.