Skip to content
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

When there is no change in file text for program, no need to update program #51626

Merged
merged 2 commits into from
Nov 29, 2022

Conversation

sheetalkamat
Copy link
Member

There have been cases where file change notification is reported twice by the native node file system events. We have setup many optimizations for this. eg we schedule updates instead of updating right away so if the events occur before that scheduled update, the program gets updated only once. But if the repeat event is received after we have updated event, we recreate program where the structure is used completely but we still have new copy. This means we don't emit program but there is still cost incurrent with binding and creating type checker and more over user gets notified that file change was detected and program will be rebuilt. So, from user perspective we are doing double compilation even though we didn't really emit anything. The main root cause for creating new program is that when getting new source file version, we don't read text and figure out if it has changed or not. We used to delay it to creating source files.
With this change, we will read file if the sourceFile state is unknown (that is we received the file change event). So, if text has not changed, we won't create new program, not report file change detected either.
Also had to modify how we read file for the sourceFile so that we can use cached text because now there are two places where we are reading source file text.

Fixes #51611

… to determine the version instead of delaying so that new program is not created if file contents have not changed
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me, good baseline improvement. I am confused about readFile though.

getSourceFile: createGetSourceFile(
(fileName, encoding) => host.readFile(fileName, encoding),
(fileName, encoding) => !encoding ? compilerHost.readFile(fileName) : host.readFile(fileName, encoding),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd to me that this looks like this, given compilerHost just defers to host.readFile too. Is it expected that CompilerHost is missing this parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are suppose to deprecate the encoding = charSet from compilerOptions Our APIs dont have that consistent everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compilerHost.readFile is normally used for module resolution only and it doesnt support passing encoding...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript watch compiles each edited file twice
4 participants