-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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
Support Typescript incremental build #42011
Comments
3.4 is officially out, which is great news! Incremental builds will hopefully save me 10+ minutes each build (I have a set of projects that take 16mins to build all of them). Out of curiosity may I ask what is currently causing this to be marked as "blocked"? |
Angular itself needs to support a TS version before it can be integrated into the tooling. |
…29872) The config path is an optional argument to `ts.parseJsonConfigFileContent`. When passed, it is added to the returned object as `options.configFilePath`, and `tsc` itself passes it in. The new TS 3.4 [incremental](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html) build functionality relies on this property being present: https://github.com/Microsoft/TypeScript/blob/025d82633915b67003ea38ba40b9239a19721c13/src/compiler/emitter.ts#L56-L57 When using The compiler-cli `readConfiguration` the config path option isn't passed, preventing consumers (like @ngtools/webpack) from obtaining a complete config object. This PR fixes this omission and should allow JIT users of @ngtools/webpack to set the `incremental` option in their tsconfig and have it be used by the TS program. I tested this in JIT and saw a small decrease in build times in a small project. In AOT the incremental option didn't seem to be used at all, due to how `ngc` uses the TS APIs. Related to https://github.com/angular/angular-cli/issues/13941. PR Close #29872
…ngular#29872) The config path is an optional argument to `ts.parseJsonConfigFileContent`. When passed, it is added to the returned object as `options.configFilePath`, and `tsc` itself passes it in. The new TS 3.4 [incremental](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html) build functionality relies on this property being present: https://github.com/Microsoft/TypeScript/blob/025d82633915b67003ea38ba40b9239a19721c13/src/compiler/emitter.ts#L56-L57 When using The compiler-cli `readConfiguration` the config path option isn't passed, preventing consumers (like @ngtools/webpack) from obtaining a complete config object. This PR fixes this omission and should allow JIT users of @ngtools/webpack to set the `incremental` option in their tsconfig and have it be used by the TS program. I tested this in JIT and saw a small decrease in build times in a small project. In AOT the incremental option didn't seem to be used at all, due to how `ngc` uses the TS APIs. Related to https://github.com/angular/angular-cli/issues/13941. PR Close angular#29872
@alan-agius4 @filipesilva Hi Guys! Congrats on the new release! Just wondering if there has been any development with this improvement since TS 3.4 is now supported. |
@RicardoVaranda https://github.com/angular/angular/blob/master/CHANGELOG.md
edit: Apparently you can't trust the Angular changelog. Angular 8.0.0 comes with TypeScript 3.4, not with 3.3. |
@MartinJohns Interestingly, 3.4 looks like it was merged into angular-8-beta-12: ef85336 |
Can confirm this, upon doing ng update it actually installed |
Is important to note that 3.4 introduce a regression that make type checking in compilation pain slow in some scenarios.
|
Angular version 8 supports (and requires) TypeScript 3.4.x. I haven't look at this again, but at the time the only problem I saw was #29872. We have to try and figure out what else (if anything) is preventing the incremental cache from being used and written. I'm not sure it can be used in the AOT compiler though, so keep that in mind. Maybe it works, maybe it doesn't. If anyone is interested in having a look at this, here's a good way to get started:
Then open At this point you'd just have to hunker down and go figure out what the logic for incremental builds in TS is trying to do, and how to work with it. There's not a lot of docs around it. When I was looking into this, I just added a lot of logs to the TS source in We use a in-memory file system for TS in |
From what I understand for incremental build to work and actually save time, files have to be emitted to outDir. If the incremental flag is true, there will be an extra tsconfig.tsbuildinfo file that holds hashes of involved files. When we build with the CLI, outDir does not seem to be used. @filipesilva is this part also using in-memory file system during build? If it is virtualized, do you know if differential build reuses the same virtual FS or a new one is created? I am quite curious about this, for my little chrome extension (for e2e tests), if I run tsc command and pass project tsconfig, first build is ~15s, 2nd ~5s (at work we might win minutes of build time) EDIT: Looks like something in public typescript API is blocking effective use of incremental build programmatically. Either way ts-loader needs to support this first: TypeStrong/ts-loader#913 . EDIT2: at work with angular 8 build alone currently takes 10 minutes (~5min for es2105 and ~5min for es5) |
@FDIM I think realistically what would happen is that we'd have to allow that file to be loaded between builds. Maybe to make sure it's loaded it is enough to give it a custom path instead of the outDir default. But at the end of each build it would still need to be persisted to disk with custom logic. I am not sure how much this would help for differential loading as each build does use different ES targets. At that point it depends on how much TS itself caches for those cases. We don't use TS loader, mind you. We have our own loader tailored to the Angular AOT compiler. So I don't think ts-loader supporting it blocks us. |
For reference, the incremental API issue on TS is microsoft/TypeScript#29978. |
My bad regarding ts-loader, I should have realized that when tinkering with the loader in CLI. I am fairly sure that writing tsconfig.tsbuildinfo file to disk would not be enough, it also needs already built files from last time to avoid compilation. Anyway, I did manage to output build files to disk after running ng build, but tsbuildinfo was not part of the output - not sure why. EDIT: I've been playing around quite a bit more with this and it seem the issue linked above needs to be handled first. Anyway, in order to speed up initial build and make use of incremental flag, ng build would have to write compiled typescript files and buildinfo file somewhere outside, so I guess there will be a need for a cache option that would enable extra emits. The other part that I haven't figured out is how will typescript will know that info file exists, it did not try to access (checking for existence or reading) it via host methods. |
Typescript already finished their implementation, so it should be possible to try it here :) |
Seems like there are no more roadblocks for Angular to support incremental builds. Some related changes that happened since then:
Docs are in progress: TS 3.5 Release notes about speed improvements and fixed regression from 3.4: |
@pppdns Does this mean I just have to set |
@wottpal |
Unfortunately to improve cold start/initial compile, additional work is needed. Api wise, new cache dir option should be enough, but it still need to be implemented. |
Anything new here ? Typescript 3.5 is now supported by Angular |
would be nice to have support of incremental build for ngc |
Also with incremental build it would be not "nice" but "awesome" to have support of composite projects. I think it would heavily help large projects to split their projects into smaller subprojects. As far as i know typescript created API for both incremental and "composite" build mode in 3.5. Well i think it has to be supported in compiler-cli first so maybe this issue should go to angular project? |
Any updates on this? Looking to implement this in a complex project that I recently upgraded to Angular 8.2. I added the incremental and tsBuildinfoFile properties but I don't see a difference (I dont even see any new files generated anywhere) |
I am not sure what happened, but the API for incremental option/program is not available in TS 3.5, only in 3.6. It will soon be released though (23rd of August according to road map). So for now I'd say this is blocked until angular packages depend on 3.6. Afterwards 2 solutions will be needed:
As for cache dir @filipesilva , I guess it would be best to reuse |
@FDIM Where did you hear that? The documentation for typescript seem to indicate this is available in 3.4: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html |
The functionality was available via |
@FDIM yes it is interesting about that API and version of typescript, because i followed release of 3.5 and fix was not present at time of release 3.5, but still they put it in changelog of 3.5 even thou i read some guy complaint that there is no API for incremental build available in 3.5, so it looks like some mess in release log, but it will be in 3.6 definitely :) |
@aruballo I've tried to use the api to see how it works, only to realize that it is not there |
How weird, I guess I'll have to wait for 3.6 before using this then. Thanks @FDIM |
Great thanks :) |
@filipesilva is correct that The same is true for the incremental build cache. One of the big requirements is having strong incremental rebuild semantics under It's very important that we get the semantics right when we move to an incremental cache. Right now under |
Just dropping in a use-case here for composite project support. We have a typescript monorepo of which one of the packages is the main front-end angular app and which consumes a number of other application-like packages in a yarn workspace (and those packages have other dependencies in the repo, such as a core ECS package, a general service interaction layer etc). Building any one of these applications will auto-build any composite dependencies it needs (and their dependencies and so on), so conceptually we only need to run a build on any one top-level application a developer's working on. For the angular frontend we have to first build all packages it depends on and get a build watcher going on each application a developer is working on. These are better than nothing but pretty slow and sometimes unreliable. It's also just generally a bit of a pain for devs to get an environment set up. So in our case it's not so much the incremental build cache (though that would be nice!) but the ability to allow typescript to recognise other composite projects in the repo with the |
I have a different use case regarding composite projects where I only have non angular component related code (so, nothing that would need JITing or AOTing) in separate projects under a monorepo/yarn workspace. I was expecting to be able to use As a workaround, I need to build the referenced projects manually before starting the main angular webpack build. I'm wondering if |
Any updates on this? |
Transfering to the FW repo as the compiler doesn't support TypeScript incremental API. Example it uses I did experiment a bit using the NGTSC plugin API with allows for a program to be supplied and patching on a small project https://github.com/ngrx/platform/tree/master/modules/component/src I saw the compilation to go from const host = ts.createIncrementalCompilerHost(compilerOptions);
const wrappedHost = ngtsc.wrapHost(host, config.rootNames, compilerOptions)
const program = ts.createIncrementalProgram({
options: compilerOptions,
rootNames: config.rootNames,
host: wrappedHost,
createProgram: ts.createEmitAndSemanticDiagnosticsBuilderProgram
})
const { ignoreForEmit } = ngtsc.setupCompilation(program.getProgram(), undefined); NB: NGTSC would also need to set versions to typechecking source files. |
@alan-agius4 awesome news! let me know if I can help you, that is very important because of slow rebuilds on large projects |
Rebuilds for a running instance ( |
Ok, what we do then with 40-60s rebuild time on ‘ng serve’? angular ignores microfrontends for several years, bazel initiative was closed before it goes to production. Angular will die if we will keep ignored that. we don’t need angular designer and features that cover corner cases But, what is community real needs:
For now, angular only fit to cms control panels, but lost competition to all public projects with lighthouse metrics, search engine optimizations and other common needs till we lose that competition - nobody cares about template type checking, di, rx, modularity and great dx. Please, think about that. I’m almost lost my faith in angular as instrument and angular as great community |
Please try to keep the issue on the original topic. If anyone has cases of 40-60 second application rebuilds, information regarding the project would greatly be appreciated by the team. If possible please open a separate issue detailing the performance situation that is being encountered. Even without access to the application code itself, the team has had success troubleshooting performance concerns when performance profiles have been provided. If needed, a team member can also provide assistance with capturing the performance profiles for analysis once the issue has been opened. |
The most important time is the incremental rebuild during the development process that is repeated hundred times. |
That’s not really what this issue is about. Incremental TypeScript API only improves subsequent cold builds as retrieves the old program data from disk. |
Yep, that's why I wanted to stress where the importance lies because |
Isn't that a little naïve? When you change something after running When you change something that a lot of other pieces of your application depend upon there'll be a lot of unnecessary recompilation throughout the 'recompilation tree'. All for the incremental change that looked trivial. Surely some of that compilation would benefit from the Typescript incremental cache. Is this issue basically dead? It's 3 years old, and while I periodically find it and read through the updates it looks like it's effectively been abandoned. I just don't buy the excuse that 'ng serve already does incremental so it wouldn't have much effect`. I realize these things are always complex, but saving 1 second that adds up. Also I would love for a cold build to be faster! Q: When am I most likely to get distracted and pick up my phone? |
@simeyla if you want, you can try nx. If a project is big enough, I think NX is the way to go. Angular CI is good until the size of the project is too big |
Next step: followup with our tooling team and determine the potential benefits of this (vs. the rather large implementation cost) |
Hi! Is there any update on this? Is it planned to include it? Thanks! |
Is this now supported for Angular 18? I received the following error on
I don't have the tsBuildInfoFile option set in my tsconfig (and |
The CLI does indeed use incremental TS builds, if caching is enabled. OTOH, The CLI does set Edit: the CLIs behavior is being changed in angular/angular-cli#28161 |
🚀 Feature request
Description
Support of Typescript incremental build https://devblogs.microsoft.com/typescript/announcing-typescript-3-4-rc/
The text was updated successfully, but these errors were encountered: