Skip to content

Commit

Permalink
Use singlethreaded execution when there is only one CPU.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton committed Aug 26, 2024
1 parent d1b3d3e commit 8f87821
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
10 changes: 2 additions & 8 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ type StateDB struct {
StorageUpdated atomic.Int64
AccountDeleted int
StorageDeleted atomic.Int64

singlethreaded bool
}

// New creates a new state from a given trie.
Expand Down Expand Up @@ -197,10 +195,6 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
return sdb, nil
}

func (s *StateDB) MakeSingleThreaded() {
s.singlethreaded = true
}

// SetLogger sets the logger for account update hooks.
func (s *StateDB) SetLogger(l *tracing.Hooks) {
s.logger = l
Expand Down Expand Up @@ -858,7 +852,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
var (
start = time.Now()
)
workers := newWorkerGroup(s.singlethreaded)
workers := newWorkerGroup()
if s.db.TrieDB().IsVerkle() {
// Whilst MPT storage tries are independent, Verkle has one single trie
// for all the accounts and all the storage slots merged together. The
Expand Down Expand Up @@ -1233,7 +1227,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) {
start = time.Now()
root common.Hash
)
workers := newWorkerGroup(s.singlethreaded)
workers := newWorkerGroup()
// Schedule the account trie first since that will be the biggest, so give
// it the most time to crunch.
//
Expand Down
5 changes: 3 additions & 2 deletions core/state/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package state

import (
"errors"
"runtime"

"golang.org/x/sync/errgroup"
)
Expand All @@ -12,8 +13,8 @@ type workerGroup interface {
Wait() error
}

func newWorkerGroup(singlethreaded bool) workerGroup {
if singlethreaded {
func newWorkerGroup() workerGroup {
if runtime.NumCPU() == 1 {
return &inlineWorkerGroup{}
} else {
var grp errgroup.Group
Expand Down

0 comments on commit 8f87821

Please sign in to comment.