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

RemoteActorRefProvider address paring, caching and resolving improvements #5273

Merged
merged 41 commits into from
Oct 1, 2021
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f25de15
refactor remote-actorref-provider and add tests for cache entries
Zetanova Sep 7, 2021
3fc0168
replace address-cache with actorpath-cache
Zetanova Sep 7, 2021
9a67f1c
refactor resolve with local address
Zetanova Sep 7, 2021
746f76b
refactor and cleanup
Zetanova Sep 7, 2021
bff01bb
remove volatile from fields
Zetanova Sep 7, 2021
d0f232e
Merge branch 'dev' into perf-remote-actorref-provider
Zetanova Sep 7, 2021
3dc67a5
merge upstream
Zetanova Sep 8, 2021
b458ae4
Merge branch 'perf-remote-actorref-provider' of https://github.com/Ze…
Zetanova Sep 8, 2021
2a55502
remove double equals
Zetanova Sep 8, 2021
14e88e2
cleanup
Zetanova Sep 9, 2021
762ec30
refactor to base
Zetanova Sep 9, 2021
aea2166
optimize elements list
Zetanova Sep 9, 2021
a36170f
improve actor path join
Zetanova Sep 10, 2021
aa211c7
improve actor path equals and compare
Zetanova Sep 10, 2021
1842505
cleanup
Zetanova Sep 10, 2021
f388cef
protect stack and use moveto of arraybuilder
Zetanova Sep 11, 2021
baaeea2
update api spec
Zetanova Sep 11, 2021
f86dc4b
test for jumbo actor path name support
Zetanova Sep 11, 2021
4427087
small refactors
Zetanova Sep 12, 2021
93f5d9c
add ActorPath.ParentOf(depth)
Zetanova Sep 12, 2021
d74deaa
dont copy actorpath
Zetanova Sep 12, 2021
a7a525e
use actorpath-cache and remove cache entry test
Zetanova Sep 12, 2021
d3c33e8
refactor fill array
Zetanova Sep 12, 2021
4512aec
prepair actor path cache for better deduplication
Zetanova Sep 12, 2021
ad3ca76
update api
Zetanova Sep 12, 2021
026a6fc
cache root actor path
Zetanova Sep 15, 2021
b29e242
update api
Zetanova Sep 15, 2021
9d9a2d7
remove obsolete code
Zetanova Sep 15, 2021
29eaff2
cleanup code
Zetanova Sep 15, 2021
f33929e
Merge branch 'dev' into perf-remote-actorref-provider
Aaronontheweb Sep 15, 2021
1051ed3
Merge remote-tracking branch 'upstream/dev' into perf-remote-actorref…
Zetanova Sep 15, 2021
2564415
Merge branch 'perf-remote-actorref-provider' of https://github.com/Ze…
Zetanova Sep 15, 2021
d3a0ae0
removed commented cache tests
Zetanova Sep 15, 2021
217485c
refactor span to string bulder
Zetanova Sep 15, 2021
409485f
use internal fields and ref equals
Zetanova Sep 17, 2021
9eba407
add rebase path test
Zetanova Sep 17, 2021
cc30aa1
fix possible NRE
Zetanova Sep 18, 2021
73d26ff
extend and test address parsing
Zetanova Sep 18, 2021
c13ad50
update api
Zetanova Sep 18, 2021
793b8b5
Merge branch 'dev' into perf-remote-actorref-provider
Zetanova Sep 29, 2021
8dd6e0c
Merge branch 'dev' into perf-remote-actorref-provider
Aaronontheweb Oct 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
optimize elements list
  • Loading branch information
Zetanova committed Sep 9, 2021
commit aea216692a91126108d589e181c51bab2fff477c
70 changes: 42 additions & 28 deletions src/core/Akka/Actor/ActorPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,27 @@ private static bool Validate(string chars)

private readonly Address _address;
private readonly ActorPath _parent;
private readonly int _depth;

private readonly string _name;
private readonly long _uid;

/// <summary>
/// Initializes a new instance of the <see cref="ActorPath" /> class.
/// Initializes a new instance of the <see cref="ActorPath" /> class as root.
/// </summary>
/// <param name="address"> The address. </param>
/// <param name="name"> The name. </param>
protected ActorPath(Address address, string name)
{
_address = address;
_parent = null;
_depth = 0;
_name = name;
_uid = ActorCell.UndefinedUid;
}

/// <summary>
/// Initializes a new instance of the <see cref="ActorPath" /> class.
/// Initializes a new instance of the <see cref="ActorPath" /> class as child.
/// </summary>
/// <param name="parentPath"> The parentPath. </param>
/// <param name="name"> The name. </param>
Expand All @@ -166,6 +171,7 @@ protected ActorPath(ActorPath parentPath, string name, long uid)
{
_parent = parentPath;
_address = parentPath.Address;
_depth = parentPath._depth + 1;
_name = name;
_uid = uid;
}
Expand Down Expand Up @@ -194,6 +200,11 @@ protected ActorPath(ActorPath parentPath, string name, long uid)
/// </summary>
public ActorPath Parent => _parent;

/// <summary>
/// The the depth of the actor.
/// </summary>
public int Depth => _depth;

/// <summary>
/// Gets the elements.
/// </summary>
Expand All @@ -202,15 +213,18 @@ public IReadOnlyList<string> Elements
{
get
{
var acc = new Stack<string>();
if (_depth == 0)
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

return ImmutableArray<string>.Empty;

var b = ImmutableArray.CreateBuilder<string>(_depth);
b.Count = _depth;
var p = this;
while (true)
for(var i = 0; i < _depth; i++)
{
if (p.IsRoot)
return acc.ToList();
acc.Push(p.Name);
p = p.Parent;
b[_depth - i - 1] = p.Name;
p = p._parent;
}
return b.ToImmutable();
}
}

Expand All @@ -226,15 +240,21 @@ internal IReadOnlyList<string> ElementsWithUid
{
get
{
if (this is RootActorPath) return Array.Empty<string>();
var elements = (List<string>)Elements;
elements[elements.Count - 1] = AppendUidFragment(Name);
return elements;
if (_depth == 0)
return ImmutableArray<string>.Empty;

var b = ImmutableArray.CreateBuilder<string>(_depth);
b.Count = _depth;
var p = this;
for (var i = 0; i < _depth; i++)
{
b[_depth - i - 1] = i > 0 ? p.Name : AppendUidFragment(p.Name);
p = p._parent;
}
return b.ToImmutable();
}
}



/// <summary>
/// The root actor path.
/// </summary>
Expand All @@ -244,18 +264,12 @@ public ActorPath Root
get
{
var current = this;
while (current._parent is ActorPath p)
current = p;
while (current._depth > 0)
current = current.Parent;
return current;
}
}

/// <summary>
/// Is this instance the root actor path.
/// </summary>
[JsonIgnore]
public bool IsRoot => _parent is null;

/// <inheritdoc/>
public bool Equals(ActorPath other)
{
Expand Down Expand Up @@ -284,7 +298,7 @@ public bool Equals(ActorPath other)
/// <inheritdoc/>
public int CompareTo(ActorPath other)
{
if (IsRoot)
if (_depth == 0)
{
if (other is ChildActorPath) return 1;
return StringComparer.Ordinal.Compare(ToString(), other?.ToString());
Expand All @@ -297,17 +311,17 @@ private int InternalCompareTo(ActorPath left, ActorPath right)
if (ReferenceEquals(left, right))
return 0;

if (left.IsRoot)
if (left._depth == 0)
return left.CompareTo(right);

if (right.IsRoot)
if (right._depth == 0)
return -right.CompareTo(left);

var nameCompareResult = StringComparer.Ordinal.Compare(left.Name, right.Name);
var nameCompareResult = StringComparer.Ordinal.Compare(left._name, right._name);
if (nameCompareResult != 0)
return nameCompareResult;

return InternalCompareTo(left.Parent, right.Parent);
return InternalCompareTo(left._parent, right._parent);
}

/// <summary>
Expand All @@ -317,7 +331,7 @@ private int InternalCompareTo(ActorPath left, ActorPath right)
/// <returns> ActorPath. </returns>
public ActorPath WithUid(long uid)
{
if (IsRoot)
if (_depth == 0)
{
if (uid != 0) throw new NotSupportedException("RootActorPath must have undefined Uid");
return this;
Expand Down