Skip to content

Wire up MulOperationOptimized and SubOperationOptimized to EVM #10030

Merged
siladu merged 5 commits intobesu-eth:mainfrom
siladu:wire-optimised-mul-sub
Apr 1, 2026
Merged

Wire up MulOperationOptimized and SubOperationOptimized to EVM #10030
siladu merged 5 commits intobesu-eth:mainfrom
siladu:wire-optimised-mul-sub

Conversation

@siladu
Copy link
Copy Markdown
Contributor

@siladu siladu commented Mar 12, 2026

...behind enableOptimizedOpcodes flag, enabled by default.

Noticed these were in the codebase since 57a7e7d and had prop tests in UInt256 but just weren't wired up.

macbook:

Benchmark                                        Mode  Cnt   Score   Error  Units
MulOperationBenchmark.executeOperation           avgt   15  80.569 ± 1.301  ns/op
MulOperationOptimizedBenchmark.executeOperation  avgt   15  39.681 ± 0.769  ns/op

SubOperationBenchmark.executeOperation           avgt   15  80.305 ± 5.005  ns/op
SubOperationOptimizedBenchmark.executeOperation  avgt   15  42.957 ± 1.585  ns/op

TODO:

  • Check UInt256PropertyBasedTest tests are valid
  • Mainnet regression
  • Hoodi full sync

… enableOptimizedOpcodes flag

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
@siladu siladu marked this pull request as ready for review April 1, 2026 07:07
Copilot AI review requested due to automatic review settings April 1, 2026 07:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Wires previously-existing optimized MUL and SUB opcode implementations into the EVM interpreter behind the enableOptimizedOpcodes flag (default-enabled per description), and adds JMH benchmarks for the optimized variants.

Changes:

  • Route opcodes 0x02 (MUL) and 0x03 (SUB) to optimized implementations when enableOptimizedOpcodes is enabled
  • Fix constructor naming and success result constant usage in MulOperationOptimized
  • Add JMH benchmarks for MulOperationOptimized and SubOperationOptimized

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
evm/src/main/java/org/hyperledger/besu/evm/operation/MulOperationOptimized.java Fixes class internals to align with MUL semantics (constructor + success result).
evm/src/main/java/org/hyperledger/besu/evm/EVM.java Routes MUL/SUB opcodes to optimized implementations behind the config flag.
ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/SubOperationOptimizedBenchmark.java Adds benchmark harness for optimized SUB execution.
ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/MulOperationOptimizedBenchmark.java Adds benchmark harness for optimized MUL execution.

Comment on lines +256 to +263
case 0x02 ->
evmConfiguration.enableOptimizedOpcodes()
? MulOperationOptimized.staticOperation(frame)
: MulOperation.staticOperation(frame);
case 0x03 ->
evmConfiguration.enableOptimizedOpcodes()
? SubOperationOptimized.staticOperation(frame)
: SubOperation.staticOperation(frame);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

runToHalt is on a hot path, and these new cases add more repeated calls to evmConfiguration.enableOptimizedOpcodes() during opcode dispatch. Consider caching the flag once (e.g., a local final boolean optimized = evmConfiguration.enableOptimizedOpcodes();) and using that in the switch cases to avoid repeated virtual/interface calls during interpretation.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@ahamlat ahamlat left a comment

Choose a reason for hiding this comment

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

🚢

@siladu siladu enabled auto-merge (squash) April 1, 2026 11:09
@siladu siladu disabled auto-merge April 1, 2026 11:10
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
@siladu siladu enabled auto-merge (squash) April 1, 2026 11:15
@siladu siladu merged commit a833928 into besu-eth:main Apr 1, 2026
46 checks passed
@siladu siladu deleted the wire-optimised-mul-sub branch April 1, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants