Skip to content

Optimize interpreter for INTEGER type operations#283

Merged
fglock merged 1 commit into
masterfrom
optimize-interpreter-integer-ops
Mar 7, 2026
Merged

Optimize interpreter for INTEGER type operations#283
fglock merged 1 commit into
masterfrom
optimize-interpreter-integer-ops

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 7, 2026

Summary

Profile-guided optimizations for the bytecode interpreter, targeting INTEGER type operations:

  • InterpreterState.setCurrentPc: Changed from pop/push on ArrayDeque to direct array mutation (O(1))
  • BitwiseOperators: Added fast-paths for &, |, ^, <<, >> that skip type checks when both operands are INTEGER
  • MathOperators: Added fast-paths for +, -, * that skip blessedId() and getNumber() calls
  • CompareOperators: Added fast-paths for <, <=, >, >=, ==, != that skip blessedId() and getNumber() calls

Profile Results (before → after)

Hotspot Before After
InterpreterState.setCurrentPc 11 samples 0 (eliminated)
getDefinedBoolean 20 samples 0 (eliminated)
ArrayDeque.push/addFirst 22 samples 0 (eliminated)
looksLikeNumber 21 samples 12 samples (-43%)

Benchmark (life_bitpacked.pl, 3000 generations, 100x100 grid)

Mode Time
JVM backend ~2.0s
Interpreter (optimized) ~4.5s

The interpreter is now ~2.3x slower than the JVM backend, which is reasonable for an interpreter.

Test plan

  • Quick sanity test for math, compare, and bitwise operations
  • Full test suite

Generated with Devin

Add fast-paths for common operations when both operands are INTEGER:
- InterpreterState: O(1) PC updates using mutable array instead of pop/push
- BitwiseOperators: Skip type checks for &, |, ^, <<, >>
- MathOperators: Skip blessedId/getNumber for +, -, *
- CompareOperators: Skip blessedId/getNumber for <, <=, >, >=, ==, !=

Profile-guided optimization based on JFR analysis of life_bitpacked.pl.
Eliminates overhead from getDefinedBoolean(), looksLikeNumber(), and
ArrayDeque operations in the hot path.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 8f8f34d into master Mar 7, 2026
2 checks passed
@fglock fglock deleted the optimize-interpreter-integer-ops branch March 7, 2026 16:12
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