Repository navigation
A source import is parsed once per compile, not each time a module generates it - #772
Merged
Merged
Conversation
…nerates it mlirGenInclude generates an import into every module that needs it (each discovery module, then theModule) and read and parsed the file again each time. powder_sandbox's checks.ts parsed its imports 211 times: 1.97 s of a 3.96 s compile (nri.ts alone 20 times). loadImportFile keeps the parsed import and the files it references in parsedImports, by canonical path. A reused tree has every node's `processed` flag cleared first, as a fresh parse has it; what else MLIRGen writes into the tree already had to hold for discovery followed by codegen of one parse. An import on the generation stack is never reloaded (filesInProgress), so no pass is still using the nodes. checks.ts --di -O0 -mm=gc: 4.10 s / 357 MB -> 2.63 s / 202 MB; -O3 -mm=rc: 4.82 s -> 3.25 s. LLVM IR of checks, powder_sandbox_nri and simulation is identical to main's. ctest -C Release: 6651/6651 passed. 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.
Problem
After #769, a file deep in an import chain still spends most of its compile on its imports. Profiling powder_sandbox's
checks.tsat its build flags (--di --opt_level=0 -mm=gc): 3.4 s of a 3.96 s compile is imports, and the biggest part is parsing.mlirGenIncludegenerates an import into every module that needs it (each discovery module, thentheModule), and read and parsed the file again each time.loadIncludeFile)/// <reference>.d.ts in discoverynri.tsalone was parsed 20 times.Fix (
MLIRGenModule.cpp,MLIRGenImpl.h)loadImportFilekeeps a parsed import and the files it references inparsedImports, keyed by canonical path, and reuses them.processedflag cleared first, as a fresh parse has it.filesInProgress), so no pass is still using the nodes when they are reused.Results
checks.ts--di -O0 -mm=gcchecks.ts-O3 -mm=rcpowder_sandbox_nri.ts--di -O0 -mm=gcsimulation.ts--di -O0 -mm=gcThe LLVM IR of
checks,powder_sandbox_nriandsimulationis identical to main's (30715, 8758 and 10611 lines, after normalizing generated numeric ids).Tests
ctest -C Releaseon Windows: 6651/6651 passed, includingimport-chain-deep(compile, JIT,-shared) andreference-path-import-nested.Next
Import codegen still runs 211 times (0.67 s). Cloning the ops of an import already generated, instead of generating them again, would remove most of that.
🤖 Generated with Claude Code