Skip to content
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

Issue #1766 - Lazy evaluation of ChildrenContainer.Children and ChildrenContainer.Stats #1772

Merged
merged 1 commit into from
Mar 11, 2016

Conversation

JeffCyr
Copy link
Contributor

@JeffCyr JeffCyr commented Mar 10, 2016

ChildrenContainer.Children was returning a copy of all its child. This PR change the Children and Stats property to return the lazy evaluated LINQ expression instead of a copy.

  • This is safe because the underlying collection is immutable
  • This is more efficient because:
    • No memory is allocated
    • Enumerating the children from the ImmutableDictionary is not expensive
    • The returned IReadOnlyCollection is not iterated in most case

The performance problem of issue #1766 was caused by this line:

_actor.SupervisorStrategyInternal.HandleChildTerminated(this, child, GetChildren());

(Note that the implementation of HandleChildTerminated is not touching the children parameter)

With this PR, GetChildren is lazy evaluated, so calling this method is not expensive anymore.

@Aaronontheweb
Copy link
Member

Thanks Jeff! I'll review this before I merge the other one

where childRestartStats != null
select childRestartStats.Child;

return new WrappedReadonlyCollection<IInternalActorRef>(children, InternalChildren.Count);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem: InternalChildren.Count will not be exact here, it does not take the where filter into account. (Same goes for Stats property).

@JeffCyr
Copy link
Contributor Author

JeffCyr commented Mar 11, 2016

Problem: InternalChildren.Count will not be exact here, it does not take the where filter into account. (Same goes for Stats property).

I changed the Count to be lazy evaluated too, worst case the children will be enumerated twice if the Count property is accessed.

Aaronontheweb added a commit that referenced this pull request Mar 11, 2016
Issue #1766 - Lazy evaluation of ChildrenContainer.Children and ChildrenContainer.Stats
@Aaronontheweb Aaronontheweb merged commit 228131a into akkadotnet:dev Mar 11, 2016
@JeffCyr JeffCyr deleted the childrencontainer-lazyeval branch May 22, 2016 06:47
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