-
Notifications
You must be signed in to change notification settings - Fork 20.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rlp, trie: faster trie node encoding #24126
Conversation
rlp.Encode
frlp.Encode
|
This work may or may not overlap with the generated encoders from @fjl. Could you PTAL Felix? |
I think this PR is valuable and we should check how it impacts performance of types.DeriveSha. This requires integrating the fast encoder into StackTrie. |
@fjl just pushed StackTrie stuff. |
77a00b4
to
7486437
Compare
There are some definite improvements to be had through this approach:
Doesn't seem to affect DeriveSha though
|
The fast encoder is especially efficient to encode full-nodes full of child nodes. In the case of DeriveSha200, that produces 200 short-nodes but only 16 full-nodes. So it's reasonable that does not affect the second approach. |
Hey, this is just to let you know I haven't forgotten about this PR! I have just published another PR where the encoder buffer is exposed in a slightly different way: #24251. The |
Okey. I'll update my PR when that merged. |
7486437
to
e228b5f
Compare
@fjl I just pushed a new commit using rlp.EncoderBuffer. |
This is a pretty solid performance improvement now:
|
if err := n.EncodeRLP(&h.tmp); err != nil { | ||
panic("encode error: " + err.Error()) | ||
} | ||
n.encode(h.encbuf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like shortNodeToHash
and fullNodeToHash
are identical now, so can maybe be merged into one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit more efficient not to merge them because encode
can be called directly instead of through the interface. But I agree that it's silly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change speeds up trie hashing and all other activities that require RLP encoding of trie nodes by approximately 20%. The speedup is achieved by avoiding reflection overhead during node encoding. The interface type trie.node now contains a method 'encode' that works with rlp.EncoderBuffer. Management of EncoderBuffers is left to calling code. trie.hasher, which is pooled to avoid allocations, now maintains an EncoderBuffer. This means memory resources related to trie node encoding are tied to the hasher pool. Co-authored-by: Felix Lange <fjl@twurst.com>
This change speeds up trie hashing and all other activities that require RLP encoding of trie nodes by approximately 20%. The speedup is achieved by avoiding reflection overhead during node encoding. The interface type trie.node now contains a method 'encode' that works with rlp.EncoderBuffer. Management of EncoderBuffers is left to calling code. trie.hasher, which is pooled to avoid allocations, now maintains an EncoderBuffer. This means memory resources related to trie node encoding are tied to the hasher pool. Co-authored-by: Felix Lange <fjl@twurst.com>
This change speeds up trie hashing and all other activities that require RLP encoding of trie nodes by approximately 20%. The speedup is achieved by avoiding reflection overhead during node encoding. The interface type trie.node now contains a method 'encode' that works with rlp.EncoderBuffer. Management of EncoderBuffers is left to calling code. trie.hasher, which is pooled to avoid allocations, now maintains an EncoderBuffer. This means memory resources related to trie node encoding are tied to the hasher pool. Co-authored-by: Felix Lange <fjl@twurst.com>
This change speeds up trie hashing and all other activities that require RLP encoding of trie nodes by approximately 20%. The speedup is achieved by avoiding reflection overhead during node encoding. The interface type trie.node now contains a method 'encode' that works with rlp.EncoderBuffer. Management of EncoderBuffers is left to calling code. trie.hasher, which is pooled to avoid allocations, now maintains an EncoderBuffer. This means memory resources related to trie node encoding are tied to the hasher pool. Co-authored-by: Felix Lange <fjl@twurst.com>
rlp package is usually efficient. But it's expensive to encode interface type values. Trie node is of nested interface type.