Description
Bug Report
π Search Terms
watch, watchOptions, TSC_WATCHFILE
π Version & Regression Information
I don't think this is a new issue. The behavior is the same between the latest official release (4.4.3) and the latest dev release (4.5.0-dev.20210926).
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about watchOptions
β― Playground Link
N/A
π» Code
Tested on a medium TypeScript codebase that contains ~1110 TypeScript files and an average amount of node_modules
.
π Actual behavior
This issue concerns steady-state CPU usage when running tsc --watch
. When I say "steady-state", I mean the CPU usage after the initial compilation is done and TypeScript is just watching files, none of which are changing.
Case 1
TSC_WATCHFILE
environment variable not set. tsconfig.json
has
"watchOptions": {
"fallbackPolling": "dynamicPriority"
}
Steady-state CPU usage: ~6.5%
Case 2
TSC_WATCHFILE
environment variable not set. tsconfig.json
has
"watchOptions": {
"watchFile": "useFsEvents",
"watchDirectory": "useFsEvents",
"fallbackPolling": "dynamicPriority"
}
Steady-state CPU usage: ~0.1%
Case 3
TSC_WATCHFILE = UseFsEventsWithFallbackDynamicPolling
. No watchOptions
in tsconfig.json
.
Steady-state CPU usage: ~0.1%
π Expected behavior
According to the TypeScript 3.8 release notes, the defaults for watchFile
and watchDirectory
are useFsEvents
. Unless these defaults were changed in a later TypeScript version, my "Case 1" and "Case 2" should have exhibited the same CPU usage.
It makes sense that "Case 2" and "Case 3" had the same CPU usage, since the environment variable is just a different way of setting the same options.
Overall, the desired behavior is that tsc --watch
uses as little CPU as possible while still doing a good job of watching files using the default watchOptions.
π Related links
- TypeScript Handbook: Configuring Watch
- 2019 Johnny Reilly blog post on TSC_WATCHFILE
- 2019 issue posted by Johnny Reilly about watch performance
π» Test environment
Windows 10
Node 14.17.6
AMD Ryzen 5 2600 Six-Core Processor
PowerShell 7.1.4