Repository navigation
Compile time: interfaces and one very large function (2,000 interfaces: 7.3 s -> 5.0 s; 16,000 ifs: 21.7 s -> 11.2 s) - #866
Merged
Conversation
… and the plan for a table of them Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…erfaces: 7.3 s -> 5.0 s) MLIR generation asked theModule.lookupSymbol "is there a symbol of this name?" for every stub of a null interface's vtable, every thunk and every instance of a generic function, and the lookup walks the module. It now keeps the symbols of each module by name (symbolsOfModule, lookupModuleSymbol): a function is heard of at pushFunction, the one way a function enters a module, and a global at createGlobalVariable. A name that is not in the table is not in the module. A name with no operation in it - a global of a dummy run, which is erased unseen, or two symbols of one name - is still looked up by the scan. An exception's records are made once for a type and a module (mlirGenRttiForType). Every `throw` and typed `catch` handed its type to MLIRRTTIHelperVC, which looked each record up by name and scanned the module for the last global, to make nothing: the records were there. The helper makes its globals unseen, so the symbol table is made again when a call of it added to the module, and the last global of the module stays remembered when it is not called. MLIR generation of 2,000 interfaces took 3.1 s and 3.6 times that for twice as many; it takes 1.0 s and doubles with the source. TSLANG_VERIFY_LLVM_GLOBALS_INDEX checks every answer of the table against the scan, and calls the helper again for a type it was called for: it must add nothing. Release suite on Windows x64 with and without it; LLVM IR unchanged on the 150 largest tests. The Linux helper was read (each record sits behind an "already there" lookup), not run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…: 1.7 s -> 0.9 s) Lowering an `if`, a loop, a `switch`, a label or a return splits the block it is in. Under the conversion driver rewriter.splitBlock moves the rest of the block into the new one operation by operation and records every move, to undo it if the conversion fails: a block of n `if`s moved n^2/2 operations. These patterns do not fail once they have split, so they split with Block::splitBlock, one splice the driver does not hear of. If the conversion fails elsewhere and is undone, the block stays split; the pass has failed and the function is not used - a compile error raised in this pass gives the same message and exit code. The `try` lowering is unchanged. TypeScriptToAffineLoweringTSFuncPass on one function of 2,000 `if`s took 0.89 s and 3.9 times that of 1,000; the whole compile now takes 0.9 s and doubles with the source up to 4,000 (8,000 is 3.0x that, not looked at). shapes.ps1: -Sizes accepts a comma list when run with pwsh -File. Release suite on Windows x64, with and without TSLANG_VERIFY_LLVM_GLOBALS_INDEX; LLVM IR unchanged on the 150 largest tests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n twice 4,000 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…00 ifs: 21.7 s -> 11.2 s) Block::splitBlock is one splice, but the splice sets the parent of every operation it moves, so lowering n `if`s of one block was still n^2/2 steps: a quarter of the samples for a function of 8,000. The function's own blocks are now split before the conversion starts (splitFunctionBlocksAhead): after each operation whose lowering splits its block, from the last one of a block to the first, so that each split moves only what lies between two of them; each part ends in a branch to the next, since the conversion driver walks blocks in dominance order. The pattern of such an operation erases that branch and takes the block it went to as the block it would have split off. Blocks of nested regions are left as they were generated: the patterns of the operations around them expect that. One function of n `if`s: 4.8 s at 8,000 and 11.2 s at 16,000, from 6.9 s and 21.7 s; TypeScriptToAffineLoweringTSFuncPass grew 7.3x from 4,000 to 8,000 and now grows with the source. Release suite on Windows x64, with and without TSLANG_VERIFY_LLVM_GLOBALS_INDEX; LLVM IR unchanged on the 150 largest tests. One run had an access violation in test-own-no-counting-own_field_chain_let: it happens about once in 300 to 500 runs with the compiler from before #862 too. Co-Authored-By: Claude Fable 5.2 <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.
Follow-up to #862-#865. This fixes the two cases those left growing faster than the source: interfaces, in MLIR generation, and one very large function.
Object file, no optimisation,
--no-default-lib, Windows x64, Release compiler:ifstatementsifstatementsifstatementsAll 14 shapes of
tslang/benchmarks/compile-time/shapes.ps1now take 1.7-2.3 times as long for twice the source at n = 1,000 to 2,000.The fixes
MLIR generation tables each module's symbols. It asked
theModule.lookupSymbol"is there a symbol of this name?" for every stub of a null interface's vtable, every thunk and every instance of a generic function, and that lookup walks the module. It now keeps the symbols of each module by name (symbolsOfModule,lookupModuleSymbol): a function is heard of atpushFunction, the one way a function enters a module, and a global atcreateGlobalVariable. A name that is not in the table is not in the module. A name with no operation recorded - a global of a dummy run, which is erased unseen, or two symbols of one name - is still looked up by the scan.An exception's records are made once per type and module (
mlirGenRttiForType). Everythrowand typedcatchhanded its type toMLIRRTTIHelperVC, which looked each record up by name and scanned the module for the last global, and made nothing because the records were there. The helper makes its globals unseen, so the symbol table is made again by a scan when a call of it added to the module.MLIR generation of 2,000 interfaces took 3.1 s, and 3.6 times that of 1,000; it takes 1.0 s and doubles with the source.
A block is split in one step. Lowering an
if, a loop, aswitch, a label or a return splits the block it is in. Under the conversion driverrewriter.splitBlockmoves the rest of the block one operation at a time and records every move for undo, so a block of nifs moved n^2/2 operations. These patterns now callBlock::splitBlock. If the conversion fails elsewhere and is undone, the block stays split; the pass has failed and the function is not used. Thetrylowering is unchanged.A function's blocks are split before its lowering. Even one splice sets the parent of every operation it moves, which was a quarter of the samples for a function of 8,000
ifs. The function's own blocks are now split before the conversion (splitFunctionBlocksAhead), after each operation whose lowering splits, from the last of a block to the first, each part ending in a branch to the next. The pattern of such an operation erases the branch and takes the block it went to as its continuation. Blocks of nested regions are left as generated.docs/compile-time-work.mdis updated;shapes.ps1 -Sizesaccepts a comma list underpwsh -File.Testing
On the last commit:
TSLANG_VERIFY_LLVM_GLOBALS_INDEXset, which now also checks every answer of the new symbol table against the scan and calls the exception-record helper again for a type it was called for (it must add nothing): no difference logged.test-borrow-facts-*failures, on my machine only (the build cache'sCMAKE_ARnames an MSVC toolset that is no longer installed; they pass with the installedlib.exe). One access violation intest-own-no-counting-own_field_chain_let, which is not from this change: see below.--opt_level=3and-mm=rc: 450 of 453 identical. The other three are00param_assigned_owned.ts, whose output differs from run to run with any compiler.if) gives the same message and exit code as before.Not covered
TypeScriptToLLVMLoweringPassand the canonicalizer grow about 3 times there. Not looked at.tslang --emit=llvm --no-default-lib -mm=own tslang/test/tester/own/own_field_chain_let.tsends with an access violation about once in 300 to 500 runs. The compiler from before Compile time: no module scan for every new global (2,000 classes: 100 s -> 3 s) #862 does the same (2 of 1,000 runs).🤖 Generated with Claude Code