Repository navigation
perf(check): ctx_dead searches the scope in place instead of copying it first - #1965
Merged
nicolas-abril merged 1 commit intoNov 2, 2026
Merged
Conversation
Contributor
Merged
5 of 8 tasks
nicolas-abril
added a commit
that referenced
this pull request
Nov 2, 2026
Level order changed which @unsafe binder type a program hangs on, and the batched var columns saved about 0.02 s while dropping the error that guarded them. #1965 fixes #1955 and #1967 fixes the call spine and body_flatten, so this is now the fields #1956 still names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #1955.
ctx_deadcopied the whole scope into an array withpmap_to_arraybefore it looked at the first variable. A scope with n local empty matches (\{}) calls it n times, so the copies grew as O(n² log n) while the search itself stopped at the first variable.Change (
bend2/bend.tsonly):pmap_anywalks the tree in place, next topmap_to_array, andctx_deaduses it. It visits the same nodes in the same order (value, then left, then right) and stops at the same first empty type, soterm_wnfandbook_adtrun on the same variables in the same order. No cache and no memo: the search only skips the copy (#993, #1075).Measured on the issue's program with n
x = {\{} : Unit -> Quant}lines,--check-only:ctx_dead, beforeCopies were counted with a temporary counter, since removed. Times are medians of 7 runs, before and after alternated.
None of the checker benches calls
ctx_dead, and their medians of 5 alternated runs stay within noise: compute_1600 508 → 505 ms, defs_12800 297 → 297, generics_3200 382 → 384, proofs_3200 823 → 833, trees_400 803 → 798. So this only matters for scopes with many empty matches.On Linux, medians of 7: n = 1024 77 → 43 ms, 4096 982 → 199 ms, 8192 4,042 → 609 ms; checker benches compute_1600 609 → 613, defs_12800 361 → 368, generics_3200 458 → 455, proofs_3200 922 → 929, trees_400 1142 → 1140.
Verification (macOS arm64, Bun 1.4.2; Linux arm64 (Docker, Debian 13, Bun 1.4.2, clang 19))
ctx_dead, n = 1 to 1024, macOS: the table abovetests/, interpreter, before vs after, macOS and Linux: no difference (on macOSproof/app/main, which greets until killed, is not comparable; on Linux its output is capped at 1 MB and matches)gates/repo.ts: 54/54 (bend.ts 44,566 / 48,000 ttok)tsc -p bend2/pack/tsconfig.json: the same 7 errors before and after, all already on maingates/test.ts,gates/perf.ts: run on the minis