Skip to content

Commit

Permalink
Improve MurmurHash string hash memory footprint (#5028)
Browse files Browse the repository at this point in the history
* Reduce memory footprint

* Fix enumerator, off by 1 error
  • Loading branch information
Arkatufus authored May 24, 2021
1 parent 6f5b003 commit 3f8fa29
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.Akka.AspNetCore", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerializationBenchmarks", "benchmark\SerializationBenchmarks\SerializationBenchmarks.csproj", "{2E4B9584-42CC-4D17-B719-9F462B16C94D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DDataStressTest", "examples\Cluster\DData\DDataStressTest\DDataStressTest.csproj", "{44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DDataStressTest", "examples\Cluster\DData\DDataStressTest\DDataStressTest.csproj", "{44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 3 additions & 3 deletions src/contrib/cluster/Akka.DistributedData/ORSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,9 @@ private ORSet<T> MergeRemoveDelta(RemoveDeltaOperation delta)
{
while (deleteDots.MoveNext())
{
var curr = deleteDots.Current;
deleteDotNodes.Add(curr.Key);
deleteDotsAreGreater &= (thisDot != null && (thisDot.VersionAt(curr.Key) <= curr.Value));
var current = deleteDots.Current;
deleteDotNodes.Add(current.Key);
deleteDotsAreGreater &= (thisDot != null && (thisDot.VersionAt(current.Key) <= current.Value));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int Compare(Address x, Address y)
if (result != 0) return result;
result = string.CompareOrdinal(x.System, y.System);
if (result != 0) return result;
result = string.CompareOrdinal(x.Host ?? "", y.Host ?? "");
result = string.CompareOrdinal(x.Host ?? string.Empty, y.Host ?? string.Empty);
if (result != 0) return result;
result = (x.Port ?? 0).CompareTo(y.Port ?? 0);
return result;
Expand Down
6 changes: 3 additions & 3 deletions src/core/Akka/Util/MurmurHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,20 @@ public static int StringHash(string s)
{
unchecked
{
var sChar = s.ToCharArray();
var span = s.AsSpan();
var h = StartHash((uint)s.Length * StringSeed);
var c = HiddenMagicA;
var k = HiddenMagicB;
var j = 0;
while (j + 1 < s.Length)
{
var i = (uint)((sChar[j] << 16) + sChar[j + 1]);
var i = (uint)((span[j] << 16) + span[j + 1]);
h = ExtendHash(h, i, c, k);
c = NextMagicA(c);
k = NextMagicB(k);
j += 2;
}
if (j < s.Length) h = ExtendHash(h, sChar[j], c, k);
if (j < s.Length) h = ExtendHash(h, span[j], c, k);
return (int)FinalizeHash(h);
}
}
Expand Down

0 comments on commit 3f8fa29

Please sign in to comment.