-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different watchFile and watchDirectory options through environment variable #21243
Conversation
…l being passed to the host)
…ries through watchFile
f21ebe9
to
4eba27b
Compare
The drop with these options: localBuilt.zip |
I tested the various options with TypeORM (~20k cloc) on macOS 10.13.3 (APFS), CPU values read from Activity Monitor with 1s Update Frequency.
Each time I modified a few files to see if the changes are noticed (they were) and also to see how long it takes to notice the change (with
I'm not sure if this is particularly helpful to you so feel free to suggest some scenarios people should test. I currently use |
@jiripospisil Thank you for trying this out and getting back.
|
@mhegazy The PR is updated to add the custom polling intervals etc to get more feedback on it as well and ready to merge as then it would be available in nightlys to get more feedback. |
efe498b
to
c5b21d4
Compare
mtime: Date; | ||
} | ||
|
||
/* @internal */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const enum ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need it not to be const enum so that we can set custom levels. https://github.com/Microsoft/TypeScript/pull/21243/files#diff-cc0eed295cd2bad794329f871b2669fdR90
Ping @mhegazy |
src/compiler/sys.ts
Outdated
|
||
const nodeVersion = getNodeMajorVersion(); | ||
const isNode4OrLater = nodeVersion >= 4; | ||
nodeSystem.watchFile = getWatchFile(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need nodeSystem in these function calls? can we just use the functions directelly and move these in the object literal above?
return useNonPollingWatchers ? | ||
createNonPollingWatchFile() : | ||
// Default to do not use polling interval as it is before this experiment branch | ||
(fileName, callback) => fsWatchFile(fileName, callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the lambda needed? why not just return fsWatchFile;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We weren't passing the polling interval before to the fsWatchFile and hence the lambda.. (to ignore pollingInterval being passed)
I'm still investigating but it looks like, after this change, every poll of a non-existent folder (in particular, |
Are you using some environment variable to change default behavior? tsserver logs would be helpful to investigate.. |
So far, the most suspicious change in my environment is using Node 8. I'm trying to get set up on a clean box. |
Filed #22494 |
fs.watch
andfs.watchFile
provided by node, both have pros and cons.fs.watch
uses file system events to notify the changes in the file/directory. But this is OS dependent and the notification is not completely reliable and does not work as expected on many OS. Also there could be limit on number of watches that can be created, eg. linux and we could exhaust it pretty quickly with programs that include large number of files. But because this uses file system events, there is not much CPU cycle involved.fs.watchFile
uses polling and thus involves CPU cycles. But this is the most reliable mechanism to get the update on the status of file/directory.By default we use to use
fs.watchFile
to watch source files, config files and missing files (missing file references) that means the CPU usage depends on number of files in the program.fs.watch
is used to watch directories (eg. source directories included by config file, failed lookup location directories etc) These can handle the missing precision in notifying about the changes. But recursive watching is supported on only Windows and OSX. That means we need something to replace the recursive nature on other OS.This PR provides the different watchFile and watchDirectory options through environment variable:
watching of files is selected by setting
TSC_WATCHFILE
to"PriorityPollingInterval"
- usefs.watchFile
but will use different polling intervals for source files, config files and missing files."DynamicPriorityPolling"
- use a dynamic queue where in the frequently modified files will be polled at shorter interval and the files unchanged will be polled less frequently"UseFsEvents"
- usefs.watch
which uses file system events (but might not be accurate on different OS) to get the notifications for the file changes/creation/deletion. Note that few OS eg. linux has limit on number of watches and failing to create watcher usingfs.watch
will result it in creating using fs.watchFile"UseFsEventsWithFallbackDynamicPolling"
- this is similar to "UseFsEvents" except on failing to create watch using fs.watch, the fallback watching happens through dynamic polling queues (as explained in "DynamicPriorityPolling")UseFsEventsOnParentDirectory
- this watched parent directory of the file withfs.watch
(using file system events)fs.watchFile
with 250ms as the timeout for any file watchingThe watch directory on platforms that dont support recursive directory watching is supported through recursively creating directory watcher for the child directories using different options selected by
TSC_WATCHDIRECTORY
"RecursiveDirectoryUsingFsWatchFile"
- usefs.watchFile
to watch the directories"RecursiveDirectoryUsingDynamicPriorityPolling"
- use dynamic polling queue to poll changes to the directoryfs.watch
to watch child directoriesThis is prototype is to get feedback for issues: #19762, #19989, #20017, #20023