Repository navigation
Compile time of a function of many any operations: 45 s -> 4.7 s - #976
Merged
Merged
Conversation
…inaryArithmeticControlFlowGraphNotTooLarge) The tsc sweep's binaryArithmeticControlFlowGraphNotTooLarge (1300 lines of `any` arithmetic in one function) compiled in a steady 45 s, near the sweep's 60 s limit with 8 jobs: it timed out now and then. - A discovery pass (dummyRun) made a generic instance again for each call: its module, thrown away, does not keep the function, so mlirGenFunctionLikeDeclaration found none. With its type arguments given, the instance's type from the function map is what the pass needs. Every `x[k]` of an `any` made `___any_key<any>` and its `___unbox`es again: 2740 instances for 100 reads; now 12. - markAnyAdapterCalls looks at the module's top-level functions only, not every op of the module after each `x[k]` or call of an `any`. - OwnedReturnConsumptionPass::releaseDiscardedTemporaries found the ways out of a block, and where a temporary's stretch ends, by walking the rest of the block for each temporary; they are the block's, found once (BlockScan, exitsOf). The releases at the stretches' ends go in after the loop, so a block's op order is not numbered again for each. - UnwindReleasePass::releaseAtUnwindExits walked each pad's handler once for each resource: the handler's reads are collected once a pad, a resource's aliases once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Nov 21, 2026
…min -> 10.6 s) (#977) * rc: a temporary is released right after its last use, not at the end of its block Under -mm=rc OwnedReturnConsumptionPass gave a discarded temporary back where its stretch of the block ends, so every temporary was live across every call after it: each call that may throw got a cleanup pad giving back all of them (UnwindReleasePass), quadratic code - binaryArithmeticControlFlowGraphNotTooLarge (1300 lines of `any` arithmetic) took ~27 min to compile under rc, 860 s of it in LLVM's optimizer. - lastUseInBlock: the op of the block holding the last use of the value under any of its names (what users make of it unless it comes with a reference of its own, what a conditional hands on, loads of a local it is stored into); none when a use can't be followed, and the release stays where it was. The release goes right after that op; nested exits after it owe nothing. rc only: own's passes read where releases are. - UnwindReleasePass: a value whose release dominates the call is given back already and owes nothing (the walk on from the call for its release went to the end of the function, and in a loop found the next turn's); a resource's aliases and a release's hand-over test are answered once. rc compile of that file: ~27 min -> 10.5 s; n=200 synthetic: 13.7 s -> 1.6 s, cleanup releases linear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * rc release at last use: not for a named const or a view; tests read the releases in front of a yield - A `const` holding the value itself (OWNED_RESULT_NAMED) is a local: given back where its scope ends, as an object let go of earlier is seen (Shared.count, a WeakRef's deref) - stack-promotion/shared_handle. - A view (an interface made of an object literal's copy) is the block it shows: the first `use(<I>o)` gave it back and the literal's block, born with no count, was freed before the second (own_interface_literal_views under rc hung at exit). A view's users are followed as the value's (NewInterface is marked owned). - generator-temporaries.cmake counts the releases in front of each yield instead of reading the ops right before it; own-mlirgen-matches-rc compares with the releases left out (their places are each model's). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * TSLANG_ISSUES 154: compile time of a function of many any operations (gc #976, rc release at last use) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
The tsc sweep's
binaryArithmeticControlFlowGraphNotTooLargesometimes timed out. It is not flaky: it is one function of 1300 lines ofanyarithmetic that took a steady 45 s to compile, against the sweep's 60 s limit with 8 jobs running. It now takes 4.7 s (7.2 s inside the sweep).Fixes
dummyRun) rebuilt a generic instance on every call. Its module is thrown away and doesn't keep the function, somlirGenFunctionLikeDeclarationnever found the one made by the previous call. When the type arguments are given explicitly, the pass now takes the instance's type from the function map instead. Everyx[k]of ananyrebuilt___any_key<any>and its___unboxhelpers: 2740 instances for 100 reads, now 12. Readingx[k]200 times went from 8.6 s to 0.26 s.markAnyAdapterCallslooks only at the module's top-level functions, instead of walking every op of the module after eachx[k]or call of anany.OwnedReturnConsumptionPass, 2.7 s -> ~0. For each temporary,releaseDiscardedTemporariesused to walk the rest of the block, nested regions included, to find the block's exits and where the temporary's stretch ends. These belong to the block, so they are now found once per block (BlockScan,exitsOf). The releases at the end of each stretch are inserted after the loop, so the block's op order is no longer renumbered for every temporary. The releases and their positions are the same as before.UnwindReleasePass::releaseAtUnwindExitswalked each landing pad's handler once per resource. It now collects the handler's reads once per pad and each resource's aliases once.Still open: under -mm=rc the same file takes much longer (24 min before this change). Temporaries are released at the end of their block, so each call that may throw gets a cleanup pad that releases every temporary made before it. The generated code grows quadratically, and LLVM's optimizer spends most of the time on it. A fix would release temporaries after their last use, which is a change of its own.
Tests: full ctest locally, 8776 tests, 0 failed. Full tsc compiler-tests sweep: 3256 passing, the same as before, with no regressions.
🤖 Generated with Claude Code