nim-eth/eth
Jacek Sieka 00c91a1dca
Ordered trie for computing roots (#744)
Root encoding is on the hot path for block verification both in the
consensus (when syncing) and execution clients and oddly consititutes a
significant part of resource usage even though it is not that much work.

While the trie code is capable of producing a transaction root and
similar feats, it turns out that it is quite inefficient - even for
small work loads.

This PR brings in a helper for the specific use case of building tries
of lists of values whose key is the RLP-encoded index of the item.

As it happens, such keys follow a particular structure where items end
up "almost" sorted, with the exception for the item at index 0 which
gets encoded as `[0x80]`, ie the empty list, thus moving it to a new
location.

Armed with this knowledge and the understanding that inserting ordered
items into a trie easily can be done with a simple recursion, this PR
brings a ~100x improvement in CPU usage (360ms vs 33s) and a ~50x
reduction in memory usage (70mb vs >3gb!) for the simple test of
encoding 1000000 keys.

In part, the memory usage reduction is due to a trick where the hash of
the item is computed as the item is being added instead of storing it in
the value.

There are further reductions possible such as maintaining a hasher per
level instead of storing hash values as well as using a direct-to-hash
rlp encoder.
2024-10-08 20:02:58 +02:00
..
common Add times_rlp and headers_rlp modules (#743) 2024-10-04 17:19:59 +02:00
db results: use standalone repo (#687) 2024-05-30 14:46:57 +02:00
keyfile Align core types with execution spec (#733) 2024-09-29 10:52:19 +02:00
net Align core types with execution spec (#733) 2024-09-29 10:52:19 +02:00
p2p discv5: migrate to minilru (#741) 2024-10-03 12:34:38 +02:00
rlp Ordered trie for computing roots (#744) 2024-10-08 20:02:58 +02:00
trie Ordered trie for computing roots (#744) 2024-10-08 20:02:58 +02:00
utp Align core types with execution spec (#733) 2024-09-29 10:52:19 +02:00
async_utils.nim better async timeout wait (#659) 2024-01-16 18:12:47 +01:00
bloom.nim Align core types with execution spec (#733) 2024-09-29 10:52:19 +02:00
common.nim Align core types with execution spec (#733) 2024-09-29 10:52:19 +02:00
eip1559.nim Add a helper for calculating the EIP1559 base fee 2022-08-18 23:36:45 +03:00
keyfile.nim Add build_dcli target and add it to CI (#344) 2021-04-06 13:33:24 +02:00
keys.nim Align core types with execution spec (#733) 2024-09-29 10:52:19 +02:00
p2p.nim Align core types with execution spec (#733) 2024-09-29 10:52:19 +02:00
rlp.nim remove remaining `int` holdouts in rlp (#737) 2024-09-30 18:32:36 +02:00
trie.nim binary tries: remove (#684) 2024-05-26 09:57:59 +02:00