From 641c96e7d2046793615328610bec74b216a87f69 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 21 Dec 2024 13:49:58 +0000 Subject: [PATCH] Allocate single byte keys once (#7952) --- src/Nethermind/Nethermind.Trie/PatriciaTree.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Trie/PatriciaTree.cs b/src/Nethermind/Nethermind.Trie/PatriciaTree.cs index dfe0f01319f..3f17f845008 100644 --- a/src/Nethermind/Nethermind.Trie/PatriciaTree.cs +++ b/src/Nethermind/Nethermind.Trie/PatriciaTree.cs @@ -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; @@ -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}");