-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: concurrency and memory improvements for execution layer
Description This PR refers to the code optimization done by `BSC`, which mainly includes the following parts: 1. Do BlockBody verification concurrently. 2. Do the calculation of intermediate root concurrently. 3. Commit the MPTs concurrently. 4. Preload accounts before processing blocks. 5. Make the snapshot layers configurable. 6. Reuse some objects to reduce GC. 7. Add shared_pool for `stateDB` to improve cache usage. References - bnb-chain/bsc#257 - bnb-chain/bsc#792 --------- Co-authored-by: j75689 <j75689@gmail.com>
- Loading branch information
Showing
73 changed files
with
1,298 additions
and
447 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package gopool | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/panjf2000/ants/v2" | ||
) | ||
|
||
const ( | ||
// DefaultAntsPoolSize is the default expire time of ants pool. | ||
defaultGoroutineExpireDuration = 10 * time.Second | ||
) | ||
|
||
var ( | ||
// defaultPool is the default ants pool for gopool package. | ||
defaultPool *ants.Pool | ||
) | ||
|
||
func init() { | ||
// Init a instance pool when importing ants. | ||
pool, err := ants.NewPool( | ||
ants.DefaultAntsPoolSize, | ||
ants.WithExpiryDuration(defaultGoroutineExpireDuration), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defaultPool = pool | ||
} | ||
|
||
// Submit submits a task to pool. | ||
func Submit(task func()) error { | ||
return defaultPool.Submit(task) | ||
} | ||
|
||
// Running returns the number of the currently running goroutines. | ||
func Running() int { | ||
return defaultPool.Running() | ||
} | ||
|
||
// Cap returns the capacity of this default pool. | ||
func Cap() int { | ||
return defaultPool.Cap() | ||
} | ||
|
||
// Free returns the available goroutines to work. | ||
func Free() int { | ||
return defaultPool.Free() | ||
} | ||
|
||
// Release Closes the default pool. | ||
func Release() { | ||
defaultPool.Release() | ||
} | ||
|
||
// Reboot reboots the default pool. | ||
func Reboot() { | ||
defaultPool.Reboot() | ||
} |
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
Oops, something went wrong.