Skip to content

opt(interpreter): use feed_gas_direct() in compute_block_gas_costs#812

Open
keke1251 wants to merge 1 commit into
jarchain:masterfrom
keke1251:opt/interpreter-gas-cost-fastpath
Open

opt(interpreter): use feed_gas_direct() in compute_block_gas_costs#812
keke1251 wants to merge 1 commit into
jarchain:masterfrom
keke1251:opt/interpreter-gas-cost-fastpath

Conversation

@keke1251
Copy link
Copy Markdown

Summary

This PR optimizes the compute_block_gas_costs() function in the PVM interpreter by using feed_gas_direct() for the fast path (~90% of instructions).

Changes

  • Before: All instructions went through fast_cost_from_raw() + sim.feed(&fc)
  • After: ~90% of instructions use feed_gas_direct() which avoids constructing FastCost structure

Performance Impact

  • Reduces memory allocations during gas cost computation
  • Eliminates unnecessary FastCost struct construction for common instructions

Testing

  • All 133 interpreter tests pass (cargo test -p javm)
  • Gas cost calculations remain identical

Related Issues


Note: This is a targeted optimization that maintains exact gas semantics while improving computation efficiency.

Replace FastCost struct construction with direct simulator feeding
for ~90% of instructions (fast path).

This avoids heap allocation and reduces memory copying,
matching the approach from PR jarchain#750.

Changes:
- Use feed_gas_direct() instead of fast_cost_from_raw() + sim.feed(&fc)
- Fall back to slow path only for branches/overlaps/moves
- All 133 tests pass
@github-actions
Copy link
Copy Markdown
Contributor

Genesis Review

Comparison targets:

How to review

Post a comment with the following format (rank from best to worst):

/review
difficulty: <commit1>, <commit2>, ..., <commitN>, currentPR
novelty: <commit1>, <commit2>, ..., <commitN>, currentPR
design: <commit1>, <commit2>, ..., <commitN>, currentPR
verdict: merge

Use the short commit hashes above and currentPR for this PR.
Each line ranks all comparison targets + this PR from best to worst.

To meta-review another reviewer's comment, react with 👍 or 👎.

liuyiyi185 added a commit to liuyiyi185/jar that referenced this pull request Apr 28, 2026
Fast path for ~90% of instructions (loads, stores, ALU, immediates,
terminators) via GasSimulator::feed_direct(), which takes register indices
directly and avoids constructing a FastCost struct.

Only instructions requiring context-dependent cost computation (ecalli,
load_imm_jump, conditional branches 181..=255, and unrecognised opcodes)
fall back to fast_cost_from_raw() + feed().

Closes jarchain#812
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant