perf: investigate VM optimization opportunities#44
Merged
danielsreichenbach merged 1 commit intomainfrom Feb 25, 2026
Merged
Conversation
Add #[inline] annotations to table.get(), get_int(), get_str(), get_hash(), and next(). These are called on every OP_GETTABLE, OP_SETTABLE, and table iteration step. Benchmarking shows LLVM already inlines these within the crate in release builds, so no measurable performance change in same-crate usage. The annotations ensure inlining for cross-crate consumers. Investigation of other optimizations (upvalue ref caching, precall inlining, arena EntryState elimination) found: - Upvalue ref caching: Vec::clone at frame entry adds 18M heap allocations for fib(35), making it slower. Borrow checker prevents holding a slice reference while mutating state. - precall/poscall inlining: increases execute() code size, causing instruction cache pressure. Net negative. - Arena EntryState elimination: requires unsafe to skip the redundant Occupied/Free match (compiler cannot prove the invariant that generation match implies Occupied). perf stat shows the ~2.2x overhead is structural: rilua executes 2.6x more instructions than PUC-Rio for the same work, due to bounds-checked arena access, Val enum discriminant checks, and Result propagation. These are distributed across every VM instruction and cannot be eliminated without unsafe code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#[inline]annotations to table lookup functions (get, get_int, get_str, get_hash, next)Investigation Results
What was tried
#[inline]on table lookups#[inline]on precall/poscallRoot cause analysis
perf statcomparison on fib(35):The ~2.2x overhead is dominated by instruction count (2.6x more code executed), not cache misses or branch mispredictions. The extra instructions come from:
These are distributed across every VM instruction and are the structural cost of safe Rust without
unsafe.Test plan