Repository navigation
Skip repeated DP searches for unchanged stack runs - #15
Merged
RobinLinus merged 1 commit intoSep 10, 2026
Merged
Conversation
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.
When a contiguous fixed-stack-op run cannot shrink,
apply_local_rulescurrently repeats the entire suffix dynamic program at every following instruction. For 512 consecutiveOP_TOALTSTACKoperations, that means 1,411,036 symbolic-window queries even though the first DP solve has already considered every suffix.Remember the unchanged run's end within the current pass, reducing this case to 5,566 queries.
stack_run_replacementnow reports the consumed run length even when it finds no shorter replacement. Only redundant DP calls are skipped: all other local rules continue running at each index, and the marker is recreated for each fixpoint pass. Compiler options, window sizes, rewrite candidates, stack-peak checks, and underflow requirements are unchanged.The reuse is valid because the source instructions and
PrefixFactsare immutable throughout oneapply_local_rulescall. If a suffix had any saving, the DP's unchanged-prefix edges would propagate it to the run's first entry. Therefore an unchanged whole-run optimum proves every suffix unchanged under the exact same facts used by subsequent calls. The implementation keeps emitting instructions through the existing local-rule loop rather than skipping that loop.Validation against base
124b561ed75ac3ec4c6ad99207d8dcdd3bc67180:cargo test --locked --workspace --all-features -- --skip fields::passes all 66 tests (22 library, 16 integration, 28 macro); the diagnostic benchmark is ignored by default and was run separately.c9b59372f57934e7bff761f4a35a000e0016779fc6ad263c6f23a3916303b50c. All five active primitive metric tests also pass without changing the recorded metrics. With the lab's BLAKE3 resource-test repair (runtime witness inputs and observable digest output), the full non-field lab suite passes under this compiler override: 409 unit tests, 18 integration tests, and 6 documentation tests; 24 existing tests are ignored and 143 field tests filtered. The lab's dependency pin remains unchanged; this is an isolated candidate integration run.git diff --checkpass.The included bounded benchmark warms the rewrite tables and asserts identical output bytes. Run it with
cargo test --locked --release --workspace --all-features benchmark_unchanged_stack_runs -- --ignored --nocapture.These are single warmed release samples on Apple M3 Max with rustc 1.98.0, while other validation was running. Timings are diagnostic, not a general speedup claim or a CI threshold; query counts are deterministic. This removes quadratic repetition of symbolic DP work on unchanged runs; other existing scans can still be quadratic.