Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

tsc -b --watch takes tens of seconds to start watching on a large project-references solution (computeDesiredWatches is O(files × dirs)) #4614

Closed

Description

@dyantako

Version

[email protected] (also reproduces on the 7.1.0-dev nightly). macOS (arm64), Node 24.
tsc execs the platform tsgo binary, so tsc -b --watch and tsgo -b --watch are the
same native code.

Summary

On a large tsc -b --watch solution, Found 0 errors. Watching for file changes. prints
within a couple of seconds, but no filesystem watch is actually registered until
computeDesiredWatches returns
, which on a large solution takes tens of seconds. Any
edit made during that window is silently lost (fsevents does not replay pre-arm events),
so the watch appears dead. Plain tsc --watch (single project, no -b) is unaffected.

Repro

https://github.com/dyantako/tsgo-b-watch-repro

npm install
npm run setup      # generates 15 projects x 1500 shared node_modules packages
npm run watch      # tsc -b --watch --preserveWatchOutput

Watching for file changes. prints within ~2s, then the process pegs a CPU core before
any watch exists. On this solution that is ~85s. To confirm nothing is watched yet:
edit a file within the first minute → nothing happens; edit again after the CPU drops to
idle → picked up in ~1s. A single small project returns in milliseconds, so this only
appears at solution scale.

Cause

computeDesiredWatches (internal/execute/build/orchestrator.go) is O(total input +
buildinfo files × number of desired watch dirs). It calls watchmanager.IsDirCoveredByWatch
for every input file, every buildinfo file, and every package.json ancestor across all
projects, and that helper linearly scans the entire desired-dirs map:

// watchmanager.go
func IsDirCoveredByWatch(dirs map[string]bool, dir string, opts) bool {
    for wdir, recursive := range dirs { /* ContainsPath / ComparePaths */ }  // scans ALL
}

On the repro: 23,745 buildinfo files × ~1,534 desired dirs. Realpath is only ~130ms of
the total, so the cost is the coverage scan, not I/O. ReconcileWatches (which actually
registers the watches) runs only after computeDesiredWatches returns, which is why the
process looks idle to the user while the watch is still dead.

Activity

  1. mt-bt commented on Aug 14, 2026

    @mt-bt

    Is there any plan to backport this to 7.0.x?

    We upgraded from @typescript/native-preview to [email protected] (npm latest) and hit this in a pnpm monorepo. On a package with ~630 files and 6 project references, tsc -b --watch sits at ~110% CPU for about 3 minutes after printing Watching for file changes, and edits made during that window are dropped, so the watch looks dead.

    Confirmed fixed on the nightlies: 7.1.0-dev.20260728.1 still reproduces, 7.1.0-dev.20260730.1 does not.

    Since 7.0.2 is latest and 7.1 stable isn't until November, a 7.0.x patch would help.

  2. jakebailey commented on Aug 14, 2026

    @jakebailey
    Member

    Yes, after #4918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions