This repository has been archived by the owner on Feb 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rlp, trie: faster trie node encoding (#24126)
commit ethereum/go-ethereum@65ed1a6. 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. This also refactors some functions in rlp package. goos: linux goarch: amd64 cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ DeriveSha200/std_trie-8 725.1µ ± 31% 613.8µ ± 37% ~ (p=0.481 n=10) DeriveSha200/stack_trie-8 572.3µ ± 10% 493.1µ ± 13% -13.85% (p=0.005 n=10) geomean 644.2µ 550.1µ -14.61% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ DeriveSha200/std_trie-8 287.4Ki ± 0% 283.0Ki ± 0% -1.53% (p=0.000 n=10) DeriveSha200/stack_trie-8 56.34Ki ± 0% 42.43Ki ± 0% -24.69% (p=0.000 n=10) geomean 127.2Ki 109.6Ki -13.88% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ DeriveSha200/std_trie-8 2.931k ± 0% 2.917k ± 0% -0.46% (p=0.000 n=10) DeriveSha200/stack_trie-8 1.462k ± 0% 1.246k ± 0% -14.77% (p=0.000 n=10) geomean 2.070k 1.907k -7.90% │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Prove-8 664.0µ ± 21% 450.2µ ± 27% -32.20% (p=0.000 n=10) VerifyProof-8 8.643µ ± 18% 9.009µ ± 33% ~ (p=0.684 n=10) VerifyRangeProof10-8 99.18µ ± 25% 67.60µ ± 67% ~ (p=0.089 n=10) VerifyRangeProof100-8 496.3µ ± 20% 487.0µ ± 33% ~ (p=0.739 n=10) VerifyRangeProof1000-8 5.149m ± 32% 4.095m ± 49% ~ (p=0.971 n=10) VerifyRangeProof5000-8 19.79m ± 60% 19.16m ± 28% ~ (p=0.631 n=10) VerifyRangeNoProof10-8 499.0µ ± 15% 422.8µ ± 29% -15.25% (p=0.035 n=10) VerifyRangeNoProof500-8 1.747m ± 30% 1.417m ± 24% -18.91% (p=0.023 n=10) VerifyRangeNoProof1000-8 3.025m ± 29% 2.239m ± 33% -25.98% (p=0.009 n=10) geomean 750.9µ 622.6µ -17.09% │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ HashFixedSize/10-8 60.30µ ± 19% 44.84µ ± 17% -25.64% (p=0.000 n=10) HashFixedSize/100-8 205.9µ ± 32% 145.2µ ± 19% -29.48% (p=0.000 n=10) HashFixedSize/1K-8 1326.5µ ± 23% 939.2µ ± 25% -29.20% (p=0.002 n=10) HashFixedSize/10K-8 14.77m ± 25% 12.74m ± 19% ~ (p=0.075 n=10) HashFixedSize/100K-8 135.2m ± 19% 104.1m ± 18% -23.03% (p=0.003 n=10) geomean 2.011m 1.520m -24.43% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ HashFixedSize/10-8 11.729Ki ± 0% 9.752Ki ± 0% -16.85% (p=0.000 n=10) HashFixedSize/100-8 58.56Ki ± 0% 49.23Ki ± 0% -15.93% (p=0.000 n=10) HashFixedSize/1K-8 578.1Ki ± 0% 481.5Ki ± 0% -16.72% (p=0.000 n=10) HashFixedSize/10K-8 6.019Mi ± 0% 4.985Mi ± 0% -17.18% (p=0.000 n=10) HashFixedSize/100K-8 59.53Mi ± 0% 49.29Mi ± 0% -17.20% (p=0.000 n=10) geomean 683.5Ki 568.8Ki -16.78% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ HashFixedSize/10-8 149.0 ± 0% 142.0 ± 0% -4.70% (p=0.000 n=10) HashFixedSize/100-8 772.0 ± 0% 739.0 ± 0% -4.27% (p=0.000 n=10) HashFixedSize/1K-8 7.443k ± 0% 7.099k ± 0% -4.62% (p=0.000 n=10) HashFixedSize/10K-8 77.09k ± 0% 73.32k ± 0% -4.89% (p=0.000 n=10) HashFixedSize/100K-8 767.8k ± 0% 730.5k ± 0% -4.86% (p=0.000 n=10) geomean 8.729k 8.321k -4.67% Co-authored-by: Felix Lange <[email protected]>
- Loading branch information
Showing
11 changed files
with
195 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package trie | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/rlp" | ||
) | ||
|
||
func nodeToBytes(n node) []byte { | ||
w := rlp.NewEncoderBuffer(nil) | ||
n.encode(w) | ||
result := w.ToBytes() | ||
w.Flush() | ||
return result | ||
} | ||
|
||
func (n *fullNode) encode(w rlp.EncoderBuffer) { | ||
offset := w.List() | ||
for _, c := range n.Children { | ||
if c != nil { | ||
c.encode(w) | ||
} else { | ||
w.Write(rlp.EmptyString) | ||
} | ||
} | ||
w.ListEnd(offset) | ||
} | ||
|
||
func (n *shortNode) encode(w rlp.EncoderBuffer) { | ||
offset := w.List() | ||
w.WriteBytes(n.Key) | ||
if n.Val != nil { | ||
n.Val.encode(w) | ||
} else { | ||
w.Write(rlp.EmptyString) | ||
} | ||
w.ListEnd(offset) | ||
} | ||
|
||
func (n hashNode) encode(w rlp.EncoderBuffer) { | ||
w.WriteBytes(n) | ||
} | ||
|
||
func (n valueNode) encode(w rlp.EncoderBuffer) { | ||
w.WriteBytes(n) | ||
} | ||
|
||
func (n rawNode) encode(w rlp.EncoderBuffer) { | ||
w.Write(n) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.