Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R] performance improvement in many aspects #257

Merged
merged 10 commits into from
Jul 29, 2021
Merged

[R4R] performance improvement in many aspects #257

merged 10 commits into from
Jul 29, 2021

Conversation

unclezoro
Copy link
Collaborator

@unclezoro unclezoro commented May 26, 2021

Description

This PR tries to improve the performance of BSC.

Rationale

Part of Block Processing can be parallel, and the layer of the snapshot is too deeper for the current implementation. This PR focus on:

  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. Cherry-pick the RLP improvement from go-ethereum.
  8. Other minor improvements.

Example

The testing result on an 8 core 2.5G Hz Linux VM:

  1. The full sync speed on the main-net is 40% faster.
  2. The execution of an BEP20 transfer is 50% faster.

Changes

New command flags: --triesInMemory

Preflight checks

  • build passed (make build)
  • tests passed (make test)
  • manual transaction test passed

Already reviewed by

...

Related issues

... reference related issue #'s here ...

@unclezoro unclezoro force-pushed the improve_8 branch 13 times, most recently from 62904a0 to 5bdb7b4 Compare May 31, 2021 07:35
@unclezoro unclezoro force-pushed the improve_8 branch 17 times, most recently from 0a1cc10 to e750b5d Compare June 7, 2021 13:19

go p.peer.RequestHeadersByNumber(from, count, 0, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use gopool here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used when clients doing fast sync and snap sync. Not related to performance

p2p/rlpx/rlpx.go Outdated
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/rlp"
"github.com/golang/snappy"
"golang.org/x/crypto/sha3"
"github.com/oxtoacart/bpool"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
if len(accountsSlice) >= preLoadLimit {
objsChan := make(chan []*state.StateObject, runtime.NumCPU())
for i := 0; i < runtime.NumCPU(); i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make sure that len(accountsSlice) > runtime.NumCPU()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add one more condition: len(accountsSlice) > runtime.NumCPU()

core/blockchain.go Outdated Show resolved Hide resolved
@adithyaxx
Copy link

Can we get this PR merged?

@unclezoro unclezoro merged commit 2ce00ad into master Jul 29, 2021
@unclezoro unclezoro mentioned this pull request Jul 29, 2021
3 tasks
@unclezoro unclezoro deleted the improve_8 branch July 29, 2021 11:18
@j75689 j75689 linked an issue Jul 30, 2021 that may be closed by this pull request
Copy link

@yvettep321 yvettep321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_thank you _

j75689 added a commit to j75689/bsc that referenced this pull request Mar 24, 2022
owen-reorg pushed a commit to bnb-chain/op-geth that referenced this pull request May 31, 2023
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>
Co-authored-by: realowen <131384228+realowen@users.noreply.github.com>
owen-reorg pushed a commit to bnb-chain/op-geth that referenced this pull request May 31, 2023
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>
Co-authored-by: realowen <131384228+realowen@users.noreply.github.com>
owen-reorg pushed a commit to bnb-chain/op-geth that referenced this pull request May 31, 2023
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>
brilliant-lx added a commit to brilliant-lx/bsc that referenced this pull request Oct 27, 2023
accountTrieCache and storageTrieCache were introduced in this PR:
bnb-chain#257, which is to improve performance.
Actually the performance gain is quite limitted, as there is already dirty
and clean cache for trie node.
And after big merge, these 2 cache can not be used when PBSS is enabled.
So remove these code to simplify the logic.
brilliant-lx added a commit that referenced this pull request Oct 30, 2023
accountTrieCache and storageTrieCache were introduced in this PR:
#257, which is to improve performance.
Actually the performance gain is quite limited, as there is already dirty
and clean cache for trie node.
And after big merge, these 2 cache can not be used when PBSS is enabled.
So remove these code to simplify the logic.
whw188 pushed a commit to tylerteea/mev-bsc that referenced this pull request Dec 6, 2023
accountTrieCache and storageTrieCache were introduced in this PR:
bnb-chain#257, which is to improve performance.
Actually the performance gain is quite limited, as there is already dirty
and clean cache for trie node.
And after big merge, these 2 cache can not be used when PBSS is enabled.
So remove these code to simplify the logic.
sunny2022da added a commit to sunny2022da/op-geth that referenced this pull request Apr 10, 2024
This is part of the optimizations from BSC, microbench show the change
could introduce speed up of simple erc20 transfer scenario.

The original PR of BSC: bnb-chain/bsc#257
sunny2022da added a commit to sunny2022da/op-geth that referenced this pull request Apr 10, 2024
This is part of the optimizations from BSC, microbench show the change
could introduce ~20% speed up of simple erc20 transfer scenario.

The original PR of BSC: bnb-chain/bsc#257
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BSC synchronization issues
8 participants