Repository navigation
Conversation
The language service asks for the version of every project file on each per-file diagnostics call, and getScriptVersion stat'ed the file every time: O(files²) stats. On a 2,250-file project that was most of a 100–186 s check. Caching the version per service makes it about 20–27 s with byte-identical output. Co-Authored-By: Claude Opus 5.5 (1M context) <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.
What and why
check-pug-typeswas slow on large projects. The language service asks for the version of every project file on each per-file diagnostics call, andgetScriptVersionstat'ed the file on each of those calls, so a check made O(files²)fs.statSynccalls.A CPU profile of a 185 s run on a 2,250-file project showed about 84 s of self time in
fs.statSyncalone, plus about 25 s more in fs utilities, all underhost.getScriptVersion. The actual type checking was a small part.The fix memoizes each file's version per language service: a
MapinsidecreateLanguageServiceFromTsconfig.Measured (same 2,250-file project, macOS, a loaded machine, so noisy)
The output is byte-identical: the same 10 diagnostics, and the diff of the two outputs is empty.
Behaviour notes
createLanguageServiceFromTsconfigis exported. A caller that keeps the service alive across edits must create a new one to see changed files; a code comment says so. No caller in this repo does.Tests
reads each file version once per check, not once per diagnosed file. It countsts.sys.getModifiedTimecalls per file over a full check ofexample/:npx vitest run packages/check-types/test/unit/index.test.ts: 12/12 pass. I checked that the new test fails without the fix.npm test(VS Code and vendored suites).No version bump: publishing goes through
lerna publish patchas usual.🤖 Generated with Claude Code