Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Dec 15, 2025

Summary

Optimizes the four dereferencing methods in RuntimeScalar.java to leverage JVM tableswitch bytecode for better performance.

Changes

  • arrayDeref(): Move ARRAYREFERENCE to if-check before switch, cases 0-11 in order
  • hashDeref(): Move HASHREFERENCE to if-check before switch, cases 0-11 in order
  • hashDerefNonStrict(): Move HASHREFERENCE to if-check before switch, cases 0-11 in order
  • arrayDerefNonStrict(): Move ARRAYREFERENCE to if-check before switch, cases 0-11 in order

Rationale

The JVM generates efficient tableswitch bytecode for contiguous integer cases (0-11: INTEGER through FORMAT). By moving the high-valued reference types (ARRAYREFERENCE/HASHREFERENCE with REFERENCE_BIT set) to an if-statement before the switch, we preserve this optimization while keeping the most common case as a fast path.

- arrayDeref(): Move ARRAYREFERENCE to if-check before switch, cases 0-11 in order
- hashDeref(): Move HASHREFERENCE to if-check before switch, cases 0-11 in order
- hashDerefNonStrict(): Move HASHREFERENCE to if-check before switch, cases 0-11 in order
- arrayDerefNonStrict(): Move ARRAYREFERENCE to if-check before switch, cases 0-11 in order

This optimization ensures the JVM generates efficient tableswitch bytecode
for the contiguous integer cases 0-11 (INTEGER through FORMAT), while
keeping the most common reference type checks as fast if-statements.
@fglock fglock merged commit ed85a7c into master Dec 15, 2025
2 checks passed
@fglock fglock deleted the optimize-deref-tableswitch branch December 15, 2025 15:03
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.

2 participants