perf(scripts): check:changed on Windows no longer spends minutes walking node_modules (740 s → 7.1 s median) #30736
main fromrefs/pull/30736/head·opened View on GitHubProblem#
On Windows, vp run check:changed sits for minutes before it starts any check, even when one markdown file changed. The wait is in inputKey (scripts/check-changed.ts), which hashes the ignored files that checks read (generated sources, .d.ts, .env*) so a rerun on identical inputs can print the cached summary. It lists them with:
git ls-files --others --ignored --exclude-standard -- ':(glob)**/.generated/**' ':(glob)**/.astro/**' ':(glob)**/*.d.ts' ':(glob)**/.env*' ':(exclude,glob)**/node_modules/**'
A pathspec only filters what git prints; git still walks every ignored directory, and :(exclude) and ** give it no prefix to prune on. pnpm links workspace packages into node_modules as junctions on Windows (apps/web/node_modules/@t3tools/shared is a junction to packages/shared), and the targets contain their own node_modules with more junctions. git for Windows follows them until paths reach MAX_PATH, printing tens of thousands of warning: could not open directory '...': Filename too long lines on every run.
inputKey runs once before the checks and once after a pass, so a passing run pays the walk twice.
Change#
ignoredCheckInputs in scripts/check-changed.ts replaces the single pathspec listing:
git ls-files -z --others --ignored --exclude-standard --directorylists each ignored directory (node_modules included) as onedir/entry without entering it.- Directories that hide from that listing are added by name:
git diff-files --diff-filter=DU: a tracked path replaced by an ignored directory (--directoryhides those), or an unmerged path.git ls-files -v -z: index entries taggedh(assume-unchanged) orS/s(skip-worktree), for which git never looks at the worktree, sodiff-filescannot see a replacement. Each such path isstated and added when it is now a directory.
- Ignored directories not under a
node_modulessegment are expanded once with the original command and:(literal)dir/pathspecs, which git prunes to:- A collapsed directory that the first listing already printed together with its contents is not expanded again (git prints an untracked directory whose contents are all ignored as
D/plus what is directly inside it), so a package folder left behind after a branch switch doesn't walk itsnode_modules. - Batches are bounded by the encoded command line, not by path count: each pathspec counts its UTF-16 length, a space, two quotes and one escape per
"or\, against a budget of 30,000 units (Windows allows 32,767). A path longer than the budget goes out alone and fails loudly rather than being dropped. - Every call starts with a
:(literal).git/pathspec. git computes the common prefix of all pathspecs and starts its walk there; when that prefix runs through a nested repository (a vendored folder with its own.git), git prints nothing or dies withdirectory entry not superset of prefix..git/is never listed and keeps the prefix empty. This is based on git's observed behaviour on 2.34 to 2.47, not on its source.
- A collapsed directory that the first listing already printed together with its contents is not expanded again (git prints an untracked directory whose contents are all ignored as
- The same four rules as the globs (
.generated/.astroancestor,*.d.ts,.env*, never under anode_modulesdirectory) are applied in JavaScript, and the result is sorted. An ignored nested repository printed by an expansion (dist/,vendor-ignored/lib/) is kept as its directory name, as the old command printed it. - Both listings use
-z, so a path git would quote (a", backslash, tab or newline, possible on Linux and macOS) is read as the real path.
What is hashed, and what differs#
Compared with the old command on the same repository, the new function lists the same paths in every tree I compared, with these exceptions:
- An ignored nested repository created inside
node_modulesis a reachable cache hit. The old command printednode_modules/r/for it (the:(exclude)glob doesn't match a directory entry); finding it needs a walk ofnode_modules, so the new code doesn't list it, and creating one reuses the cached summary. Only its name was ever hashed, and no check reads it. Outsidenode_modules, creating or deleting an ignored nested repository changes the key as before. - Paths git quotes (Linux and macOS only). The old command hashed the quoted spelling and couldn't read the file. The new code hashes the real name and contents: extra invalidation, one cache miss after updating.
- Linux, a directory name that isn't valid UTF-8. The old command listed its files with replacement characters; the new pathspec, built from the decoded name, matches nothing. Neither version could read those files, so only names were ever in the key.
- Hash order. Ignored paths are hashed in sorted (UTF-16) order rather than git's byte order. They differ only for names outside the Basic Multilingual Plane next to higher ones; the one-time effect is a cache miss.
- A directory created during the run. Directories are listed first and expanded afterwards, so one created between the git calls (milliseconds apart) is missed by that computation. The key is computed again after a passing run, so it can't be cached as passing.
- A
node_modulesbelow an expanded directory is still walked (for exampledist/node_modulesinside an expandeddist/); its entries are filtered afterwards. - Extra git calls.
diff-filesandls-files -vadd about 0.03 s here. On a sparse checkout with 30,000 skip-worktree entries the extrastatcalls cost at most about 0.5 s (two runs on a busy machine, indicative only), with correct results. - Many unstaged deletions. Every tracked path that
diff-filesreports as deleted is passed on as an expansion pathspec. In a fixture with 22,201 tracked files deleted withoutgit rm, the listing took 2.22 s median (n=8) against about 0.03 s for the old command, with identical output. Checking that each such path is now a directory before expanding it brings that to 1.79 s; I left that out of this PR to keep it small, and can add it if you want it. - Compatibility. git 2.47.0.windows.1 for the tests and timings; git 2.43 under WSL for the random comparison below; earlier revisions were compared on 2.39.2 and 2.34.1. On git 2.27 the old and new lists differ in many repositories for reasons I didn't find, so I make no claim for 2.27 or older. macOS wasn't tested.
Scope and approval#
One focused fix with no product change: check:changed selects, runs and reports the same checks. I'm submitting it under the small, focused fix exception: the defect is obvious (minutes of a pathspec-filtered walk through node_modules for a list that is normally empty), and it adds no option or behaviour. It is larger than a one-liner because a cache key must never miss a real input change, and most of the diff is the equivalence tests that pin that. If you'd rather settle the approach in an issue first, I'm happy to move it there.
Searched before opening: open and merged PRs for "check:changed", "check-changed", "ignored node_modules", "ls-files ignored". Nothing touches this listing; #23581 and #29596 changed other parts of the file.
Verification#
Windows 11 (10.0.26200), NTFS, git 2.47.0.windows.1, Node 26.12.1, below-normal priority, a worktree with a completed vp i. The only change in the tree is one new markdown file, so the only check that runs is fmt --check on it. The cache file is deleted before each timed run. Command: vp run check:changed HEAD.
One new docs/*.md file | main (499727ddad, 29,223 tracked files) | this branch (on e68e19d605, 31,561 tracked files) |
|---|---|---|
| run 1 | 833.7 s (exit code not recorded) | 8.7 s |
| run 2 | 722.5 s (exit code not recorded) | 8.1 s |
| run 3 | 796.4 s | 7.1 s |
| run 4 | 696.6 s | 6.9 s |
| run 5 | 740.1 s | 6.9 s |
| median | 740.1 s (min 696.6, max 833.7) | 7.1 s (min 6.9, max 8.7) |
| exit code | 0 for runs 3 to 5 | 0 for all five |
scripts/check-changed.ts and its test are unchanged between 499727ddad and e68e19d605, so the main runs stand for this base; they were not alternated with the branch runs. Main runs 1 and 2 show a passing format step but no recorded exit code. For runs 3 to 5 the original script and test were checked in with skip-worktree so that only the markdown file counted as a change. Two other main attempts aren't counted: one changed three files (so lint, knip, typecheck and tests ran), one was interrupted. A rerun with unchanged inputs on the branch hits the cache in 4.9 s (Nothing changed since the last passing run.). Raw rows: https://gist.github.com/Pyseph/39d10df5712b73c447479995f4f029e0
Equivalence (the set of hashed paths must not change):
vp env exec --node 26.12.1 vp test run --project root scripts/check-changed.test.ts: main 8 passed / 7 failed, this branch 12 passed / 7 failed. The 7 failures are the same on both sides and unrelated: those fixtures setGIT_CONFIG_GLOBALtoNodeOS.devNull(\\.\nulon Windows), which git for Windows rejects. The new tests use an empty global config file. (--project rootbecause vitest's dependency optimizer forapps/webaborts withos error 123on this checkout path, on main too.)- New tests: the equivalence fixture (ignored matches at the root and nested, tracked and non-ignored declarations that must not appear,
node_modulesat five depths, a left-behind package folder, a replaced tracked path, a nested repository in a tracked folder, quoted paths where the platform allows them) deep-equals the old command's output with a small budget that forces several expansion calls;--assume-unchanged,--skip-worktreeand both on replaced paths, and creating and deleting ignored nested repositories, each deep-equal to the old command;chunkByCommandLengthunit tests with long paths, emoji, backslashes, quotes and an over-budget path. Ten mutants of the function (each fix removed or miscounted) each fail at least one of these tests. - End-to-end stale-cache probe: the real
check:changedCLI in a small repository, withvite-plusreplaced by a recording stub, a persistent source edit so the early return doesn't apply, then an edit of an ignored input and a rerun. Main and this branch rerun all four steps in every scenario (assume-unchanged, skip-worktree, nested repository created, nested repository deleted); an earlier revision of this change reused the stale summary in all four, which is what thels-files -vand nested-repository handling fix. Results are in the gist above. - Fixture comparisons on Windows against the old command: negated and nested
.gitignorerules, untracked directories, names with spaces,[,',;,%and emoji, case variants, junctions including a loop, 0 to 1,200 collapsed directories, and a left-behind folder with a junction loop (0Filename too longwarnings with the change). All equal. An independent review also compared 400 random repositories on Windows with this function and 180 under WSL with a line-for-line JavaScript copy (git 2.43, on the Windows drive): no differences beyond the ones listed above.
What the tests can't show: that node_modules isn't walked, in time. They check which pathspecs git is given; the junction recursion only exists on Windows with real pnpm junctions. The timings are the evidence for the speedup. Not checked: macOS, Linux timing, git older than 2.34.
Claude Sonnet 5.5 and Claude Opus 5.5 in T3 Code (Claude Code harness).
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
a8f1b5bMacroscope's review found this PR approvable — Optimizes check:changed cache-input discovery to avoid expensive node_modules walks on Windows without changing which checks run. The impact is limited to developer tooling, with existing cache safeguards and reported equivalence probes supporting low risk.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Walkthrough
-
The check-pass cache key now uses selectively discovered ignored inputs. The discovery logic filters generated files and bounds Git arguments by command length. Tests cover filtering, path handling, and chunking.
Changes: Ignored Check-Input Discovery
Layer / File(s) Summary Input filters and command chunking
scripts/check-changed.ts,scripts/check-changed.test.tsThe script filters generated directories, declaration files, and environment files. It chunks Git arguments within a command-length budget. Tests cover filtering rules and chunk-size behavior. Ignored-path discovery and cache integration
scripts/check-changed.ts,scripts/check-changed.test.tsThe cache key now uses ignoredCheckInputsto discover ignored paths through directory listings and selective expansion. Tests compare results with the prior Git walk and cover marked paths and nested repositories.Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Possibly related PRs
- pingdotgg/t3code#23581: Added the check-pass cache and selected ignored-file inputs that this change now discovers through
ignoredCheckInputs.
Suggested labels:
bugfix,size:LSuggested reviewers:
t3dotgg,juliusmarminge - pingdotgg/t3code#23581: Added the check-pass cache and selected ignored-file inputs that this change now discovers through
Merge Risk:
Minimal · up toa8f1b-
No actionable issue remains; the change is mergeable after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: a perf fix so check:changed on Windows no longer spends minutes walking node_modules. The changeset replaces the ignored-input listing in scripts/check-changed.ts so i… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The description follows the repository template closely. It has the Problem, Change, Scope and approval, and Verification sections. The Problem section explains the Windows slowdown in inputKey, with … Full details: Title check
-
Explanation
The title names the main change: a perf fix so check:changed on Windows no longer spends minutes walking node_modules. The changeset replaces the ignored-input listing in scripts/check-changed.ts so ignored node_modules directories are not walked, which matches the title. The timing figures in the title are supported by the PR description's verification table. The title is specific and follows the conventional commit format from the template.
Full details: Description check
-
Explanation
The description follows the repository template closely. It has the Problem, Change, Scope and approval, and Verification sections. The Problem section explains the Windows slowdown in inputKey, with the failing git ls-files pathspec and the junction recursion. The Change section lists the replacement ignoredCheckInputs steps, the batching rules, and the :(literal).git/ prefix workaround. The Scope and approval section invokes the small focused fix exception and explains why the change is larger than a one-liner, and it searches for related PRs and issues. The Verification section gives Windows 11 timings with a table, exit codes, equivalence test results with the seven unrelated failures explained, fixture comparisons, and a list of what the tests cannot show. It also names the models and harness used, as the template asks. The description is thorough and specific. Two points could be tightened: the Scope section asks for explicit maintainer approval or a triaged issue, and the author instead claims the small-fix exception without a linked issue or discussion. The template also says that a prior issue or discussion is required unless the fix is very small and obvious, and the author argues that it is obvious but does not fully meet the 'very small' criterion. This is a judgment call, so the check still passes on completeness.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 8b44f42
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c958214f-424b-4acb-ac5a-a2843c983f52
Commits-
Reviewing files that changed from the base of the PR and between 8b44f42b14c8e273156474a924ccf29680dd7857 and a8f1b5b852c6ccc7e7cbcf32e51a0b112fe7688e.
Files selected for processing: 2-
scripts/check-changed.test.tsscripts/check-changed.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
Note
Written by Claude Opus 5.5 on behalf of Pyseph
Superseded by #32023: the same fix in 96 changed lines instead of 412. The replaced-path handling here (
diff-files,ls-files -v,stat) is onegit ls-files -k --directorycall there, and the equivalence checks from this PR were rerun against it. Closing this one.Pyseph(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes