Skip to content

Commit

Permalink
Remove old parallel related code
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Nov 30, 2021
1 parent c35e3b0 commit 91ed716
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 97 deletions.
66 changes: 0 additions & 66 deletions lib/trie/branch/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func Test_Branch_Encode(t *testing.T) {
testCases := map[string]struct {
branch *Branch
writes []writeCall
parallel bool
wrappedErr error
errMessage string
}{
Expand Down Expand Up @@ -179,71 +178,6 @@ func Test_Branch_Encode(t *testing.T) {
"cannot encode child at index 3: " +
"failed to write child to buffer: test error",
},
"buffer write error for children encoded in parallel": {
branch: &Branch{
Key: []byte{1, 2, 3},
Value: []byte{100},
Children: [16]node.Node{
nil, nil, nil, &leaf.Leaf{Key: []byte{9}},
nil, nil, nil, &leaf.Leaf{Key: []byte{11}},
},
},
writes: []writeCall{
{ // header
written: []byte{195},
},
{ // key LE
written: []byte{1, 35},
},
{ // children bitmap
written: []byte{136, 0},
},
{ // value
written: []byte{4, 100},
},
{ // first children
written: []byte{12, 65, 9, 0},
err: errTest,
},
},
parallel: true,
wrappedErr: errTest,
errMessage: "cannot encode children of branch: " +
"cannot encode child at index 3: " +
"failed to write child to buffer: " +
"test error",
},
"success with parallel children encoding": {
branch: &Branch{
Key: []byte{1, 2, 3},
Value: []byte{100},
Children: [16]node.Node{
nil, nil, nil, &leaf.Leaf{Key: []byte{9}},
nil, nil, nil, &leaf.Leaf{Key: []byte{11}},
},
},
writes: []writeCall{
{ // header
written: []byte{195},
},
{ // key LE
written: []byte{1, 35},
},
{ // children bitmap
written: []byte{136, 0},
},
{ // value
written: []byte{4, 100},
},
{ // first children
written: []byte{12, 65, 9, 0},
},
{ // second children
written: []byte{12, 65, 11, 0},
},
},
parallel: true,
},
"success with sequential children encoding": {
branch: &Branch{
Key: []byte{1, 2, 3},
Expand Down
4 changes: 0 additions & 4 deletions lib/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type Trie struct {
root node.Node
childTries map[common.Hash]*Trie // Used to store the child tries.
deletedKeys []common.Hash
parallel bool
}

// NewEmptyTrie creates a trie with a nil root
Expand All @@ -42,7 +41,6 @@ func NewTrie(root node.Node) *Trie {
childTries: make(map[common.Hash]*Trie),
generation: 0, // Initially zero but increases after every snapshot.
deletedKeys: make([]common.Hash, 0),
parallel: true,
}
}

Expand All @@ -54,7 +52,6 @@ func (t *Trie) Snapshot() *Trie {
generation: c.generation + 1,
root: c.root,
deletedKeys: make([]common.Hash, 0),
parallel: c.parallel,
}
}

Expand All @@ -63,7 +60,6 @@ func (t *Trie) Snapshot() *Trie {
root: t.root,
childTries: children,
deletedKeys: make([]common.Hash, 0),
parallel: t.parallel,
}

return newTrie
Expand Down
31 changes: 4 additions & 27 deletions lib/trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,35 +1131,12 @@ func Benchmark_Trie_Hash(b *testing.B) {
trie.Put(test.key, test.value)
}

trieTwo, err := trie.DeepCopy()
require.NoError(b, err)

b.Run("Sequential hash", func(b *testing.B) {
trie.parallel = false

b.StartTimer()
_, err := trie.Hash()
b.StopTimer()

require.NoError(b, err)

printMemUsage()
})
b.StartTimer()
_, err := trie.Hash()
b.StopTimer()

b.Run("Parallel hash", func(b *testing.B) {
trieTwo.parallel = true

b.StartTimer()
_, err := trieTwo.Hash()
b.StopTimer()

require.NoError(b, err)

printMemUsage()
})
}
require.NoError(b, err)

func printMemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
Expand Down

0 comments on commit 91ed716

Please sign in to comment.