Skip to content

Commit

Permalink
Clean up TrieNode.GetMemorySize (NethermindEth#7233)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Jun 29, 2024
1 parent 949589f commit fa32048
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/Nethermind/Nethermind.Trie/TrieNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,34 +784,20 @@ Keccak is null
int nodeTypeSize = 1;
/* _isDirty + NodeType aligned to 4 (is it 8?) and end up in object overhead*/

for (int i = 0; i < (_data?.Length ?? 0); i++)
object?[] data = _data;
if (data is not null)
{
if (_data![i] is null)
{
continue;
}

if (_data![i] is Hash256)
{
dataSize += Hash256.MemorySize;
}

if (_data![i] is byte[] array)
{
dataSize += MemorySizes.ArrayOverhead + array.Length;
}

if (_data![i] is CappedArray<byte> cappedArray)
{
dataSize += MemorySizes.ArrayOverhead + cappedArray.UnderlyingLength + MemorySizes.SmallObjectOverhead;
}

if (recursive)
for (int i = 0; i < data.Length; i++)
{
if (_data![i] is TrieNode node)
var child = data[i];
dataSize += child switch
{
dataSize += node.GetMemorySize(true);
}
null => 0,
Hash256 => Hash256.MemorySize,
byte[] array => MemorySizes.ArrayOverhead + array.Length,
CappedArray<byte> cappedArray => MemorySizes.ArrayOverhead + cappedArray.UnderlyingLength + MemorySizes.SmallObjectOverhead,
_ => recursive && child is TrieNode node ? node.GetMemorySize(true) : 0
};
}
}

Expand Down

0 comments on commit fa32048

Please sign in to comment.