Repository navigation
fix: emit all allocas in the init block instead of the current block - #1665
Merged
Merged
Conversation
Several libfuncs (felt252_dict_squash, squashed_dict into_entries, qm31 binary ops), the qm31 runtime binding and the trace-dump state snapshot emitted `llvm.alloca` into the libfunc's own block. When that block is part of a loop, the alloca re-executes on every iteration and the stack grows unboundedly. Route every alloca through the function's init block, which runs exactly once per call. `libfunc_qm31_bin_op` now takes the `LibfuncHelper` (like `dict_get`) so it can reach the init block, and `build_state_snapshot` takes an explicit init block argument. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
orizi
approved these changes
Oct 1, 2026
orizi
left a comment
Collaborator
There was a problem hiding this comment.
@orizi reviewed 6 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).
Benchmark results Main vs HEAD.Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
|
Benchmarking resultsBenchmark for program
|
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
11.259 ± 0.033 | 11.222 | 11.311 | 6.27 ± 0.11 |
cairo-native (embedded AOT) |
1.796 ± 0.030 | 1.767 | 1.871 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.796 ± 0.013 | 1.777 | 1.821 | 1.00 ± 0.02 |
Benchmark for program dict_snapshot
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
514.2 ± 4.9 | 508.0 | 525.3 | 1.00 |
cairo-native (embedded AOT) |
1618.5 ± 20.7 | 1594.8 | 1655.5 | 3.15 ± 0.05 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1632.4 ± 15.7 | 1602.9 | 1658.6 | 3.17 ± 0.04 |
Benchmark for program factorial_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
5.036 ± 0.038 | 4.993 | 5.128 | 2.99 ± 0.03 |
cairo-native (embedded AOT) |
1.683 ± 0.008 | 1.664 | 1.695 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.686 ± 0.017 | 1.658 | 1.712 | 1.00 ± 0.01 |
Benchmark for program fib_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
4.952 ± 0.023 | 4.912 | 4.987 | 3.06 ± 0.02 |
cairo-native (embedded AOT) |
1.616 ± 0.007 | 1.604 | 1.625 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.642 ± 0.016 | 1.616 | 1.671 | 1.02 ± 0.01 |
Benchmark for program linear_search
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
559.2 ± 7.2 | 552.9 | 575.4 | 1.00 |
cairo-native (embedded AOT) |
1641.0 ± 11.7 | 1627.9 | 1666.9 | 2.93 ± 0.04 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1666.5 ± 9.1 | 1647.8 | 1675.4 | 2.98 ± 0.04 |
Benchmark for program logistic_map
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
469.6 ± 1.7 | 466.4 | 472.6 | 1.00 |
cairo-native (embedded AOT) |
1618.2 ± 19.7 | 1602.5 | 1665.6 | 3.45 ± 0.04 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1643.3 ± 13.7 | 1621.4 | 1669.4 | 3.50 ± 0.03 |
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
Several places emitted
llvm.allocainto the libfunc's own block rather than the function's init (pre-entry) block. When that block sits inside a loop, the alloca re-executes on every iteration and the stack grows without bound.All allocas now go through the init block, which runs exactly once per function call:
felt252_dict_squash: range-check and gas pointers.squashed_dictinto_entries: result array slot.qm31binary ops: lhs/rhs operand slots.RuntimeBindingsMeta::libfunc_qm31_bin_op: result slot. Now takes theLibfuncHelperinstead of a bare&Module(same asdict_get); callers already passed the helper via deref.trace_dump::build_state_snapshot(with-trace-dumpfeature): per-variable snapshot slots emitted at every statement. Takes an explicit init block; both call sites incompiler.rspass the pre-entry block.Test plan
cargo checkwith and withoutwith-trace-dumpcargo clippy --all-targetsclean,cargo fmtappliedcargo test --lib -- qm31 felt252_dict squashed_dict(41 passed)🤖 Generated with Claude Code
This change is