perf(core/vm): optimize push2 opcode #31267#2311
perf(core/vm): optimize push2 opcode #31267#2311gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
We have a handwritten encoder for PUSH1 already, this PR adds one for PUSH2. PUSH2 is the second most used opcode as shown here: https://gist.github.com/shemnon/fb9b292a103abb02d98d64df6fbd35c8 since it is used by solidity quite significantly. Its used ~20 times as much as PUSH20 and PUSH32.
a647d7b to
83f7978
Compare
There was a problem hiding this comment.
Pull request overview
Adds a specialized, handwritten encoder for the EVM PUSH2 opcode to improve VM execution performance, similar to the existing PUSH1 fast path.
Changes:
- Switches
PUSH2execution in the Frontier jump table from the genericmakePush(2, 2)implementation to a dedicatedopPush2. - Introduces
opPush2implementation incore/vm/instructions.gointended to reduce overhead vs the generic push path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| core/vm/jump_table.go | Routes PUSH2 to the new specialized opPush2 implementation. |
| core/vm/instructions.go | Adds the new opPush2 opcode implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| // opPush2 is a specialized version of pushN | ||
| func opPush2(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { |
There was a problem hiding this comment.
opPush2 does not match the executionFunc type used by the jump table (func(pc *uint64, evm *EVM, callContext *ScopeContext)). It currently takes *EVMInterpreter as the second parameter, so assigning it to operation.execute will not compile. Update opPush2 to use the *EVM signature (similar to opPush1) so it can be referenced from the jump table.
| func opPush2(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { | |
| func opPush2(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { |
| }, | ||
| PUSH2: { | ||
| execute: makePush(2, 2), | ||
| execute: opPush2, |
There was a problem hiding this comment.
execute expects an executionFunc (func(pc *uint64, evm *EVM, callContext *ScopeContext)), but opPush2 currently has a different signature. This change will break compilation unless opPush2 is updated to match executionFunc (or you revert to makePush(2, 2)).
| execute: opPush2, | |
| execute: makePush(2, 2), |
Proposed changes
We have a handwritten encoder for PUSH1 already, this PR adds one for PUSH2.
PUSH2 is the second most used opcode as shown here: https://gist.github.com/shemnon/fb9b292a103abb02d98d64df6fbd35c8 since it is used by solidity quite significantly. Its used ~20 times as much as PUSH20 and PUSH32.
Ref: ethereum#31267
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that