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

Incremental compile can spend time type checking files with @ts-nocheck #56956

Closed
wnayes opened this issue Jan 5, 2024 · 1 comment Β· Fixed by #58592
Closed

Incremental compile can spend time type checking files with @ts-nocheck #56956

wnayes opened this issue Jan 5, 2024 · 1 comment Β· Fixed by #58592
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@wnayes
Copy link
Contributor

wnayes commented Jan 5, 2024

πŸ”Ž Search Terms

incremental, nocheck, @ts-nocheck, tsbuildinfo

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried (just latest 5.3.3 but I doubt it is new).

⏯ Playground Link

No response

πŸ’» Code

The TypeScript compiler, during a subsequent --incremental compile, can end up doing semantic analysis of source files that are marked with @ts-nocheck. This is unexpected and different from a non-incremental compile.

I have not observed error diagnostics from the nocheck file actually get printed out from a compile, however the behavior can be quite noticeable performance-wise if a significant amount of code has @ts-nocheck and undergoes incremental compile.

Specifically, checkSourceFileWorker(node) processing can occur during incremental compiles for a source file that had @ts-nocheck (or technically, checkJsDirective.enabled == false). It seems this is unique to incremental compiles. It looks to me like a nocheck file can end up being iterated through via getNextAffectedFile, and when processing occurs on it, there is no checkJsDirective.enabled check. Only getBindAndCheckDiagnosticsForFileNoCache checks checkJsDirective.enabled, which doesn't appear to be a code path used for incremental checking.

It looks like ts.skipTypeChecking is checked in more places than checkJsDirective.enabled. I happened to confirm that the extra type checking work is avoided if ts.skipTypeChecking were to be edited to include such a check, so potentially that is relevant to a possible fix.


I don't think I can create a Playground link for this, because the issue to observe is basically "extra processing only during incremental compile."

I created this repo with a small project and some example traces that demonstrate the issue:
https://github.com/wnayes/incremental-no-check

The gist of it is that the large.ts file, marked with @ts-nocheck, can end up having CPU time spent type checking it during incremental compiles. There are instructions to reproduce the issue, however the "proof" is basically this line in some traces that I committed:

https://github.com/wnayes/incremental-no-check/blob/main/traces-2/trace.json#L318

There (as well as on many following lines) we can see semantic analysis being done on large.ts, yet the workflow never involves removing @ts-nocheck.

πŸ™ Actual behavior

Incremental compiles can spend CPU time doing semantic analysis on @ts-nocheck files, which seems wasteful.

πŸ™‚ Expected behavior

Incremental compiles shouldn't do semantic analysis on @ts-nocheck files.

Additional information about the issue

No response

@sheetalkamat
Copy link
Member

This should be fixed by #58592

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
3 participants