Skip to content

Commit

Permalink
Allocate single byte keys once (#7952)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Dec 21, 2024
1 parent f8918a9 commit 641c96e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Nethermind/Nethermind.Trie/PatriciaTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace Nethermind.Trie
public class PatriciaTree
{
private const int MaxKeyStackAlloc = 64;
private readonly static byte[][] _singleByteKeys = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15]];

private readonly ILogger _logger;

public const int OneNodeAvgMemoryEstimate = 384;
Expand Down Expand Up @@ -733,7 +735,7 @@ L X - - - - - - - - - - - - - - */
if (childNode.IsBranch)
{
TrieNode extensionFromBranch =
TrieNodeFactory.CreateExtension(new[] { (byte)childNodeIndex }, childNode);
TrieNodeFactory.CreateExtension(_singleByteKeys[childNodeIndex], childNode);
if (_logger.IsTrace)
_logger.Trace(
$"Extending child {childNodeIndex} {childNode} of {node} into {extensionFromBranch}");
Expand Down

0 comments on commit 641c96e

Please sign in to comment.