-
Notifications
You must be signed in to change notification settings - Fork 4
Migrate runtime from AST post-order execution to bytecode IR + VM with execution-only benchmarks and VM stack optimization #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
621aebb
Implement bytecode compiler and VM execution pipeline
Copilot 72ecfa6
Address VM return-path review feedback
Copilot ceb93eb
Finalize VM stack return invariant handling
Copilot cb75c79
Add execution-only AST vs bytecode benchmarks and results markdown
Copilot f620115
Optimize VM value stack with preallocation and stack pointer
Copilot 38a730f
Refine VM stack pointer push/pop invariants
Copilot aa0d38b
Update execution-only benchmark data for current VM implementation
Copilot 9879a9f
test: increase vm coverage
Codex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Execution-only benchmark: AST vs Bytecode VM | ||
|
|
||
| Command: | ||
|
|
||
| ```bash | ||
| cargo bench --bench execute_expression | ||
| ``` | ||
|
|
||
| Method: | ||
|
|
||
| - Parse each expression once to AST. | ||
| - Compile the AST once to bytecode `Program`. | ||
| - Benchmark **execution only**: | ||
| - `ast.exec(&mut ctx)` | ||
| - `bytecode::execute_program(&program, &mut ctx)` | ||
| - Create a fresh context per iteration for both paths. | ||
|
|
||
| ## Results (Criterion, median) | ||
|
|
||
| | Scenario | AST exec | Bytecode exec | Delta (Bytecode vs AST) | | ||
| | --- | ---: | ---: | ---: | | ||
| | short_expression | 597.55 ns | 594.13 ns | -0.57% | | ||
| | long_expression | 2.5106 µs | 2.5698 µs | +2.36% | | ||
| | function_call | 695.27 ns | 655.10 ns | -5.78% | | ||
| | list_map_mix | 864.45 ns | 679.70 ns | -21.37% | | ||
| | ternary_chain | 493.75 ns | 494.15 ns | +0.08% | | ||
|
|
||
| ## Takeaways | ||
|
|
||
| - At pure execution level, bytecode is **not uniformly slower**. | ||
| - Bytecode is close to parity for short-expression and ternary-chain cases in this run. | ||
| - Bytecode is slower in the long arithmetic-heavy case in this run. | ||
| - Bytecode is faster in function-call and list/map construction cases in this run. | ||
| - The previous end-to-end slowdown mostly comes from the extra **compile stage per call** in `execute()` (parse + compile + run). | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot According to the current implementation, update the performance comparison data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in commit
aa0d38b.benchmarks_execution_only.mdnow reflects freshly re-run execution-only Criterion data from the current implementation (including the VM stack optimization), with updated per-scenario deltas and takeaways.Screenshot: N/A (no UI changes; benchmark documentation update only).