Skip to content

tsc -w recompiles whole project in stead of changed ts file #8660

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
life777 opened this issue May 18, 2016 · 3 comments
Closed

tsc -w recompiles whole project in stead of changed ts file #8660

life777 opened this issue May 18, 2016 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@life777
Copy link

life777 commented May 18, 2016

TypeScript Version:

I use typescript compiler 1.8.10 from npm.

Code
I use TypeScript in a project with ~500 ts files. When I type in console tsc -w and wait for the whole project is compiled, I add a small changes to one of my files. It re-compiles whole project instead of one changed file (it takes 10-25 seconds). I used node-inspector to track what the reason of such behavior. I found out that when it performs re-compilation (tsc.ts:564), it creates a new program without passing an old program as a forth parameter to the function.

I created a small project for experiments with some files and start watcher with flag --listFiles:

tsc -w --listFiles 

My tsconfig.json:

{
  "exclude": [],
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "isolatedModules": true,
    "declaration": false,
    "inlineSourceMap": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowJs": false
  }
}

Expected behavior:

It should compile only one changed file (I added a space to the calc.ts files).

Actual behavior:

It re-compiles whole files:

1

I understand that such behavior can't be added for project that should be bundled into one file.

Thanks

@ahejlsberg
Copy link
Member

The second time around with tsc -w the compiler actually does reuse syntax trees of all unmodified files (but by a different mechanism than passing a fourth argument to createProgram), thus saving the time it would take to read the files from disk and parse them. However, it type checks the entire program, and that definitely can be time consuming. Since changes in one file can cause type errors to occur in other files (e.g. imagine you delete a member from a type that is used in many files) there is really no good way to avoid this. It might be possible to construct and analyse a module dependency graph (if you're using ES6 modules) to exclude non-dependent modules, but it would be complicated by the ability of modules to augment other modules. Without a good deal of work I think we're being as incremental as we can be at the moment.

@ahejlsberg ahejlsberg added the Working as Intended The behavior described is the intended behavior; this is not a bug label May 18, 2016
@life777
Copy link
Author

life777 commented May 18, 2016

Ok, thanks.

Can the process of compiling be a bit changed? A changed file can be compiled first and js file will be created almost instantly, but after that re-compile the rest of the project.

Thanks in advance

@myitcv
Copy link

myitcv commented May 18, 2016

I believe this discussion is related?

#8479

And hence #3204 is also relevant.

@mhegazy mhegazy closed this as completed May 20, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants