Skip to content

Commit

Permalink
cleanup chunking
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Sep 12, 2024
1 parent 99ca91e commit ac89898
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions app/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
blockstm "github.com/crypto-org-chain/go-block-stm"
)

const MinimalParallelPreEstimate = 32
const MinimalParallelPreEstimate = 16

func DefaultTxExecutor(_ context.Context,
txs [][]byte,
Expand Down Expand Up @@ -239,24 +239,18 @@ func preEstimates(txs [][]byte, workers, authStore, bankStore int, evmDenom stri
}

blockSize := len(txs)
chunk := blockSize / workers
if blockSize < MinimalParallelPreEstimate || chunk == 0 {
job(0, blockSize)
} else {
var wg sync.WaitGroup
wg.Add(workers)
for i := 0; i < workers; i++ {
start := i * chunk
end := (i + 1) * chunk
if i == workers-1 {
end = blockSize
}
go func() {
defer wg.Done()
job(start, end)
}()
}
wg.Wait()
chunk := (blockSize + workers - 1) / workers
var wg sync.WaitGroup
for i := 0; i < blockSize; i += chunk {
start := i
end := min(i+chunk, blockSize)
wg.Add(1)
go func() {
defer wg.Done()
job(start, end)
}()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
}
wg.Wait()

return memTxs, estimates
}

0 comments on commit ac89898

Please sign in to comment.