Skip to content

tsc is very slow in subdirectories of larger project #36103

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

Closed
bgmort opened this issue Jan 9, 2020 · 2 comments
Closed

tsc is very slow in subdirectories of larger project #36103

bgmort opened this issue Jan 9, 2020 · 2 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@bgmort
Copy link

bgmort commented Jan 9, 2020

Maybe there's something unique to my system or my project going on here, but I'm getting very slow performance from tsc when trying to compile a single file from a subdirectory inside a larger project. The larger project is being compiled with parcel and is not using a .tsconfig file right now. I can demonstrate with a trivial example, see code below.

TypeScript Version:
Version 3.8.0-dev.20200109, 3.7, 3.1 for comparison. All had the same issue.

Search Terms:
tsc, typescript compiler very slow in subdirectories, scanning files outside of root, unused files

Code

~/somepath/lib/sound echo "var s: string = 'hello';"  > hello.ts
~/somepath/lib/sound time tsc hello.ts

real	0m5.592s # <-- very slow
user	0m9.604s
sys	0m0.473s
~/somepath/lib/sound cp hello.ts /tmp/tstmp/
~/somepath/lib/sound pushd /tmp/tstmp/
/tmp/tstmp ls
hello.ts
/tmp/tstmp time tsc hello.ts

real	0m1.916s # <-- less slow
user	0m3.089s
sys	0m0.187s

Expected behavior:
Compiler should not take >5 seconds for a trivial compilation, and should only look at files referenced by the entry file.

Actual behavior:
When compiling a single trivial file (or even trying to compile a file that does not exist) from a subdirectory within a larger project, the compilation took over 5 seconds, vs <2 in a clean directory. But even the 2 seconds for a trivial compilation seems quite slow.

Related Issues:
Lots of issues refer to slow compilation, but I did not find any describing this specific problem.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jan 10, 2020
@RyanCavanaugh
Copy link
Member

I would speculate that you have a node_modules/@types folder with a bunch of definitions in them. You can validate by passing --listFiles. By default these are picked up and error-checked; you could also try passing --skipLibCheck which would speed this up substantially.

If that's not it, then we'd need more information to try to help diagnose.

@bgmort
Copy link
Author

bgmort commented Jan 15, 2020

You are exactly right. This resolves my problem. But it makes me wonder if the default behavior can (or should) be improved. On the other hand, I know that simply running tsc is a relatively uncommon way of building, and would most often happen in a smaller project that doesn't have a large number of external types included. I guess it's probably not something that needs to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants