Skip to content
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

Implement stacktrie to improve RLP/hashing performance #244

Merged
merged 11 commits into from Feb 13, 2023
Merged

Conversation

trinhdn97
Copy link
Contributor

@trinhdn97 trinhdn97 commented Jan 5, 2023

Following #237

  • Implement stacktrie
  • Use trie.Stacktrie for block and transactions hashing instead of trie.Trie currently
name                      old time/op    new time/op    delta
DeriveSha200/trie-16     221µs ± 1%     209µs ± 0%   -5.39%  (p=0.000 n=20+19)

name                      old alloc/op   new alloc/op   delta
DeriveSha200/trie-16     287kB ± 0%      60kB ± 0%  -79.02%  (p=0.000 n=20+20)

name                      old allocs/op  new allocs/op  delta
DeriveSha200/trie-16     2.89k ± 0%     1.24k ± 0%  -57.10%  (p=0.000 n=20+20)
  • Optimize DeriveSha by exposing the RLP int-encoding and making use of it to write integers directly to a buffer
    Benchmark result is using trie.Trie only
name                      old time/op    new time/op    delta
DeriveSha200/std_trie-16     241µs ± 2%     220µs ± 0%  -8.76%  (p=0.000 n=19+16)

name                      old alloc/op   new alloc/op   delta
DeriveSha200/std_trie-16     271kB ± 0%     287kB ± 0%  +5.83%  (p=0.000 n=20+20)

name                      old allocs/op  new allocs/op  delta
DeriveSha200/std_trie-16     2.69k ± 0%     2.89k ± 0%  +7.40%  (p=0.000 n=19+20)
  • Expose and use the encoder buffer for trie RLP actions
name                      old time/op    new time/op    delta
EncodeShortNode-16           147ns ± 9%      72ns ±10%  -51.27%  (p=0.000 n=20+20)
EncodeFullNode-16           1.56µs ±28%    0.41µs ±24%  -73.76%  (p=0.000 n=20+20)
DecodeShortNode-16           197ns ±51%     165ns ± 9%  -16.32%  (p=0.000 n=18+16)
DecodeShortNodeUnsafe-16     181ns ±45%     161ns ±20%     ~     (p=0.086 n=20+20)
DecodeFullNode-16           1.26µs ±45%    1.45µs ±33%  +14.66%  (p=0.045 n=17+20)
DecodeFullNodeUnsafe-16     1.28µs ±48%    1.23µs ±23%     ~     (p=0.473 n=20+20)

name                      old alloc/op   new alloc/op   delta
EncodeShortNode-16           48.0B ± 0%     48.0B ± 0%     ~     (all equal)
EncodeFullNode-16             864B ± 0%      576B ± 0%  -33.33%  (p=0.000 n=20+20)
DecodeShortNode-16            189B ± 0%      189B ± 0%     ~     (all equal)
DecodeShortNodeUnsafe-16      141B ± 0%      141B ± 0%     ~     (all equal)
DecodeFullNode-16           1.79kB ± 0%    1.79kB ± 0%     ~     (all equal)
DecodeFullNodeUnsafe-16     1.22kB ± 0%    1.22kB ± 0%     ~     (all equal)

name                      old allocs/op  new allocs/op  delta
EncodeShortNode-16            1.00 ± 0%      1.00 ± 0%     ~     (all equal)
EncodeFullNode-16             2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=20+20)
DecodeShortNode-16            5.00 ± 0%      5.00 ± 0%     ~     (all equal)
DecodeShortNodeUnsafe-16      4.00 ± 0%      4.00 ± 0%     ~     (all equal)
DecodeFullNode-16             34.0 ± 0%      34.0 ± 0%     ~     (all equal)
DecodeFullNodeUnsafe-16       33.0 ± 0%      33.0 ± 0%     ~     (all equal)

types/transaction_test.go Outdated Show resolved Hide resolved
types/block_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rameight rameight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes

@rameight rameight merged commit 3238e51 into master Feb 13, 2023
@trinhdn97 trinhdn97 deleted the ft/stacktrie branch February 24, 2023 07:16
@rameight rameight linked an issue Jun 20, 2023 that may be closed by this pull request
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize & Improve Trie, Preparing for state trie pruner
3 participants