Refactor and optimise commit interrupt#1570
Merged
Conversation
marcello33
approved these changes
Jun 10, 2025
cffls
reviewed
Jun 10, 2025
lucca30
approved these changes
Jun 10, 2025
Contributor
lucca30
left a comment
There was a problem hiding this comment.
Looks really good to me. Nice catch @manav2401
I'll just leave a food for thoughts (not worth for this solution, but maybe can raise an optimization idea for other part of the code 😄):
- Is it possible that just checking after a few batch of OPCODES instead of each time on the loop is a worth approach?
- From what I researched no, since the cost of an atomic load is similar of a batching check.
cffls
approved these changes
Jun 16, 2025
Contributor
cffls
left a comment
There was a problem hiding this comment.
Thanks for refactoring & simplifying! Looks pretty good to me.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently, in bor, we use an interrupt context to notify the miner and EVM modules to stop block building when we hit the 2s mark to prevent delayed block announcement. While the check is pretty trivial, we do it before running every OPCODE which can lead to it using good chunk of CPU when processing transactions. An internal benchmark revealed that it used around 40% of CPU (out of the total CPU used in block building loop) on increased (~100M) gas limit block.
This is because we check for
context.Done()before running every opcode which can be non-trivial for a heavy block with too many transactions (and a lot more opcodes). We instead use a simple global atomic flag to toggle when the block building time is up and use this global flag in the EVM interpreter and miner loop to check if we want to interrupt or continue ahead.This PR also refactors how commit interrupt is handled in worker - evm interaction and simplifies it to a very good extent.
Here's a very minimalistic benchmark for both the calls.
Context done approach:
Results:
Atomic flag approach
Results:
Time for each operation is 0.4130 ns in this approach v/s 10.34 ns in the previous one.
Changes
Checklist
Testing
Manual tests
Tested it on shadow fork.
Additional comments
Please post additional comments in this section if you have them, otherwise delete it