Skip to content

Commit

Permalink
Fix memory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Jan 5, 2025
1 parent e1231a3 commit f4d1b7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Trie.Test/Pruning/TreeStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void FindCachedOrUnknown_CorrectlyCalculatedMemoryUsedByDirtyCache()
long startSize = trieStore.MemoryUsedByDirtyCache;
trieStore.FindCachedOrUnknown(null, TreePath.Empty, TestItem.KeccakA);
TrieNode trieNode = new(NodeType.Leaf, Keccak.Zero);
long oneKeccakSize = trieNode.GetMemorySize(false) + ExpectedPerNodeKeyMemorySize - MemorySizes.SmallObjectOverhead;
long oneKeccakSize = trieNode.GetMemorySize(false) + ExpectedPerNodeKeyMemorySize - MemorySizes.SmallObjectOverhead - MemorySizes.RefSize - MemorySizes.RefSize;
Assert.That(trieStore.MemoryUsedByDirtyCache, Is.EqualTo(startSize + oneKeccakSize));
trieStore.FindCachedOrUnknown(null, TreePath.Empty, TestItem.KeccakB);
Assert.That(trieStore.MemoryUsedByDirtyCache, Is.EqualTo(2 * oneKeccakSize + startSize));
Expand Down Expand Up @@ -253,7 +253,7 @@ public void Memory_with_concurrent_commits_is_correct()
tree.Commit();
}

fullTrieStore.MemoryUsedByDirtyCache.Should().Be(_scheme == INodeStorage.KeyScheme.Hash ? 540560L : 610708L);
fullTrieStore.MemoryUsedByDirtyCache.Should().Be(_scheme == INodeStorage.KeyScheme.Hash ? 556672L : 626820L);
fullTrieStore.CommittedNodesCount.Should().Be(1349);
}

Expand Down Expand Up @@ -1012,7 +1012,7 @@ public async Task Will_Not_RemovePastKeys_OnSnapshot_DuringFullPruning()

memDb.Count.Should().Be(61);
fullTrieStore.Prune();
fullTrieStore.MemoryUsedByDirtyCache.Should().Be(_scheme == INodeStorage.KeyScheme.Hash ? 552 : 708);
fullTrieStore.MemoryUsedByDirtyCache.Should().Be(_scheme == INodeStorage.KeyScheme.Hash ? 600 : 756);
}

[Test]
Expand Down
20 changes: 10 additions & 10 deletions src/Nethermind/Nethermind.Trie.Test/TrieNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,14 @@ public void Can_encode_branch_with_unresolved_children()
public void Size_of_a_heavy_leaf_is_correct()
{
Context ctx = new();
Assert.That(ctx.HeavyLeaf.GetMemorySize(false), Is.EqualTo(208));
Assert.That(ctx.HeavyLeaf.GetMemorySize(false), Is.EqualTo(224));
}

[Test]
public void Size_of_a_tiny_leaf_is_correct()
{
Context ctx = new();
Assert.That(ctx.TiniestLeaf.GetMemorySize(false), Is.EqualTo(136));
Assert.That(ctx.TiniestLeaf.GetMemorySize(false), Is.EqualTo(152));
}

[Test]
Expand All @@ -553,7 +553,7 @@ public void Size_of_a_branch_is_correct()
node.SetChild(i, ctx.AccountLeaf);
}

Assert.That(node.GetMemorySize(true), Is.EqualTo(3376));
Assert.That(node.GetMemorySize(true), Is.EqualTo(3632));
Assert.That(node.GetMemorySize(false), Is.EqualTo(176));
}

Expand All @@ -564,7 +564,7 @@ public void Size_of_an_extension_is_correct()
TrieNode trieNode = new(NodeType.Extension, key: new byte[] { 1 });
trieNode.SetChild(0, ctx.TiniestLeaf);

Assert.That(trieNode.GetMemorySize(false), Is.EqualTo(96));
Assert.That(trieNode.GetMemorySize(false), Is.EqualTo(112));
}

[Test]
Expand All @@ -574,8 +574,8 @@ public void Size_of_unknown_node_is_correct()
TrieNode trieNode = new(NodeType.Extension, key: new byte[] { 1 });
trieNode.SetChild(0, ctx.TiniestLeaf);

Assert.That(trieNode.GetMemorySize(true), Is.EqualTo(232));
Assert.That(trieNode.GetMemorySize(false), Is.EqualTo(96));
Assert.That(trieNode.GetMemorySize(true), Is.EqualTo(264));
Assert.That(trieNode.GetMemorySize(false), Is.EqualTo(112));
}

[Test]
Expand All @@ -597,7 +597,7 @@ public void Size_of_extension_with_child()
{
TrieNode trieNode = new(NodeType.Extension);
trieNode.SetChild(0, null);
trieNode.GetMemorySize(false).Should().Be(64);
trieNode.GetMemorySize(false).Should().Be(80);
}

[Test]
Expand All @@ -613,7 +613,7 @@ public void Size_of_leaf_with_value()
{
TrieNode trieNode = new(NodeType.Leaf);
trieNode.Value = new byte[7];
trieNode.GetMemorySize(false).Should().Be(104);
trieNode.GetMemorySize(false).Should().Be(120);
}

[Test]
Expand Down Expand Up @@ -711,7 +711,7 @@ public void Extension_child_as_keccak_memory_size()
trieNode.SetChild(0, child);

trieNode.PrunePersistedRecursively(1);
trieNode.GetMemorySize(false).Should().Be(112);
trieNode.GetMemorySize(false).Should().Be(128);
}

[Test]
Expand All @@ -724,7 +724,7 @@ public void Extension_child_as_keccak_clone()
trieNode.PrunePersistedRecursively(1);
TrieNode cloned = trieNode.Clone();

cloned.GetMemorySize(false).Should().Be(112);
cloned.GetMemorySize(false).Should().Be(128);
}

[Test]
Expand Down

0 comments on commit f4d1b7d

Please sign in to comment.