-
Notifications
You must be signed in to change notification settings - Fork 511
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
Fine-grained Pending
state
#1575
base: master
Are you sure you want to change the base?
Fine-grained Pending
state
#1575
Conversation
Signed-off-by: linning <[email protected]>
Interesting results. I thought the Polkadot SDK was optimized enough for this case, but the benchmark you shared suggests otherwise. Could you share the script you used for benchmarking? |
The benchmark was originally done in our testing framework for the EVM domain (an optimistic rollup based on frontier), there are too many other factors that may affect the result, so I wrote a few unit tests in frontier to demonstrate the issue easier. You can pull this branch and run the test in the last 3 commits: cargo test -r -p pallet-ethereum -- --exact tests::evm_transact_1000 --nocapture
cargo test -r -p pallet-ethereum -- --exact tests::evm_transact_4000 --nocapture
cargo test -r -p pallet-ethereum -- --exact tests::evm_transact_8000 --nocapture The last 3 commits present the case NOTE: the result is not exactly the same as the one in the PR description as this is done in the unit test in |
Could you take a look, please? @conr2d @boundless-forest |
Your tests contain some issues that should be addressed:
That said, I did observe the performance degradation you mentioned. However, there are a few considerations to take into account:
While I agree that there is potential to improve the current structure, we need to find the root cause of the performance degradation and validate it with benchmark results in a real-world environment. This should include testing in a WASM runtime with RocksDB to ensure the results are representative. |
Thank you! @conr2d
You are right, I have force-pushed the branch and updated the test as you suggested, and the result does look slightly different (take
Do you mean the read of
I agree that the test is not a rigorous benchmarking, it is more for comparison with different types of As for the root cause, I did observe (when benchmarking in our code) in
Furthermore, I checked with the unit test the current |
Regarding For more on CountedStorageMap, you can refer to this conr2d/frontier@e7a2ac9. |
@boundless-forest @crystalin What are your thoughts on this? The issue addressed in this PR appears reasonable to me, as the |
The changes make sense to me. I want to confirm once more that the changes don't pose a storage compatibility issue, as the storage is only utilized within a block, and no migration is necessary. |
Signed-off-by: linning <[email protected]>
Hey, I have updated this branch to include a To run the benchmark on your machine, pull the branch, and for the last 3 commits (which present the case
On my machine, the result is Also, this PR is updated to use the |
The
Pending
state is a list that is used to keep track of all the(transaction, status, receipt)
in the block during block execution, and then inon_finalize
these data are moved toCurrentBlock/CurrentReceipts/CurrentTransactionStatuses
for RPC service usage.Because the
Pending
state is aStorageValue<_, Vec<...>>
, which presents as a single value in the trie, appending items to the list means read,update,write to the same value, which gets slower and slower as the list grows during block execution, and depend on the number of tx in the block it can result in 3-20x of slow (see below).This PR fixes the issue by refactoring the
Pending
state, to replaceStorageValue
withStorageMap
so each tx is present as a single value in the trie, although it results in more db delete inon_finalize
but in practice, it is much faster than updating a big single list.Below is a table about the block execution time of different
Pending
states whereN
represents the total number ofEthereum::transact
in the block, each tx transfers funds from the sameAlice
account to a new different account. The test is running on aMacBook Pro, Apple M1 Pro, 10 Core(s)
Pending
statePending
statePending
state