Skip to content

Default watch options not working as expected β€” steady-state CPU usageΒ #46069

Closed
@srmagura

Description

@srmagura

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

πŸ’» Test environment

Windows 10
Node 14.17.6
AMD Ryzen 5 2600 Six-Core Processor
PowerShell 7.1.4

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions