-
Notifications
You must be signed in to change notification settings - Fork 879
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
Improve withdrawals processing performance #5026
Improve withdrawals processing performance #5026
Conversation
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
@@ -284,47 +284,49 @@ public void commit() { | |||
new BonsaiValue<>(wrappedWorldView().getCode(addr).orElse(null), null)); | |||
pendingCode.setUpdated(updatedAccount.getCode()); | |||
} | |||
if (!updatedAccount.getUpdatedStorage().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: if we flip the condition and return early, we might avoid the indentions. i.e. if (updatedAccount.getUpdatedStorage.isEmpty() {return;}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me why this improves withdrawals performance, can you please explain?
Also, it seems to be a change that will affect things other than withdrawals, so wondering what has been done to ensure we haven't regressed anything else? Would this be covered by existing automated tests or have you performed some relevant manual tests?
Finally, it's bonsai specific - what if we process withdrawals with FOREST?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like different optimisation from the one mentioned initially. I thought the optimization was to avoid the cost of the parallel streams overhead. This looks like it avoids doing unnecessary work if there is no storage to update. Which is a good thing though.
Are you planning to add an optimization to avoid the parallel stream for withdrawal balance updates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@siladu You're right, the PR description is not detailed enough. During block processing, we have 3 big consumers in terms of time processing : Transactions execution, commit the changes of each transaction to the worldstate updater and persist all the changes (in memory or on disk). During withdrawals processing, we also commit the changes of all the withdrawals to a worldstate updater but we use the same method (commit) that is used to manage all the cases (accounts deletion, storage update, storage deletion, ..etc). In the case of withdrawals, we only modify the balances, so we should just focus on accounts updates.
@jframe good point, you're totally right. I wanted to start with this first optimisation to see if it is sufficient, and avoid creating another specific method for withdrawals to keep the code simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the flamegraphs at the block processing level in the description to better see that withdrawals processing doesn't appear as it takes less time than before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding FOREST, I couldn't get more insights from the profiling as it couldn't capture anything (after my last modification). It could be interesting to do the same work with lots of transactions to see the real impact. Currently, block processing with withdrawals takes less than 2 ms, that's why it is hard to get samples on Block processing. Async Profiler, the tool I'm using, has a default frequency of 100 Hz (1 sample every 10 ms).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one minor nit pick.
datatypes/src/main/java/org/hyperledger/besu/datatypes/GWei.java
Outdated
Show resolved
Hide resolved
@@ -284,47 +284,49 @@ public void commit() { | |||
new BonsaiValue<>(wrappedWorldView().getCode(addr).orElse(null), null)); | |||
pendingCode.setUpdated(updatedAccount.getCode()); | |||
} | |||
if (!updatedAccount.getUpdatedStorage().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me why this improves withdrawals performance, can you please explain?
Also, it seems to be a change that will affect things other than withdrawals, so wondering what has been done to ensure we haven't regressed anything else? Would this be covered by existing automated tests or have you performed some relevant manual tests?
Finally, it's bonsai specific - what if we process withdrawals with FOREST?
…or the withdrawals Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
* Improve withdrawals processing performance * Add a changelog entry * refactoring + remove the changelog entry as we have not change logs for the withdrawals Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
* Improve withdrawals processing performance * Add a changelog entry * refactoring + remove the changelog entry as we have not change logs for the withdrawals Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
* Improve withdrawals processing performance * Add a changelog entry * refactoring + remove the changelog entry as we have not change logs for the withdrawals Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
* Improve withdrawals processing performance * Add a changelog entry * refactoring + remove the changelog entry as we have not change logs for the withdrawals Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H ameziane.hamlat@consensys.net
PR description
During withdrawals processing on devnet, profiling the execution showed two possible little improvements regarding performance.
The flamegraph at the block processing level
With this PR, Withdrawals processing doesn't appear in the profiling flame graph (see below) which means it is faster than before. We can check also that the withdrawals are processed for each block with this log (see 16 ws for 16 withdrawals).
The flamegraph at the block processing level
Fixed Issue(s)
Documentation
doc-change-required
label to this PR ifupdates are required.
Changelog