perf(ivy): reuse prior analysis work during incremental builds (#34288)
Previously, the compiler performed an incremental build by analyzing and resolving all classes in the program (even unchanged ones) and then using the dependency graph information to determine which .js files were stale and needed to be re-emitted. This algorithm produced "correct" rebuilds, but the cost of re-analyzing the entire program turned out to be higher than anticipated, especially for component-heavy compilations. To achieve performant rebuilds, it is necessary to reuse previous analysis results if possible. Doing this safely requires knowing when prior work is viable and when it is stale and needs to be re-done. The new algorithm implemented by this commit is such: 1) Each incremental build starts with knowledge of the last known good dependency graph and analysis results from the last successful build, plus of course information about the set of files changed. 2) The previous dependency graph's information is used to determine the set of source files which have "logically" changed. A source file is considered logically changed if it or any of its dependencies have physically changed (on disk) since the last successful compilation. Any logically unchanged dependencies have their dependency information copied over to the new dependency graph. 3) During the `TraitCompiler`'s loop to consider all source files in the program, if a source file is logically unchanged then its previous analyses are "adopted" (and their 'register' steps are run). If the file is logically changed, then it is re-analyzed as usual. 4) Then, incremental build proceeds as before, with the new dependency graph being used to determine the set of files which require re-emitting. This analysis reuse avoids template parsing operations in many circumstances and significantly reduces the time it takes ngtsc to rebuild a large application. Future work will increase performance even more, by tackling a variety of other opportunities to reuse or avoid work. PR Close #34288
This commit is contained in:

committed by
Kara Erickson

parent
50cdc0ac1b
commit
74edde0a94
@ -159,7 +159,7 @@ describe('Evaluator', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support referene to a declared module type', () => {
|
||||
it('should support reference to a declared module type', () => {
|
||||
const declared = program.getSourceFile('declared.ts') !;
|
||||
const aDecl = findVar(declared, 'a') !;
|
||||
expect(evaluator.evaluateNode(aDecl.type !)).toEqual({
|
||||
|
@ -32,13 +32,14 @@ runInEachFileSystem(() => {
|
||||
|
||||
function expectToHaveWritten(files: string[]): void {
|
||||
const set = env.getFilesWrittenSinceLastFlush();
|
||||
|
||||
const expectedSet = new Set<string>();
|
||||
for (const file of files) {
|
||||
expect(set).toContain(file);
|
||||
expect(set).toContain(file.replace(/\.js$/, '.d.ts'));
|
||||
expectedSet.add(file);
|
||||
expectedSet.add(file.replace(/\.js$/, '.d.ts'));
|
||||
}
|
||||
|
||||
// Validate that 2x the size of `files` have been written (one .d.ts, one .js) and no more.
|
||||
expect(set.size).toBe(2 * files.length);
|
||||
expect(set).toEqual(expectedSet);
|
||||
|
||||
// Reset for the next compilation.
|
||||
env.flushWrittenFileTracking();
|
||||
@ -479,7 +480,7 @@ runInEachFileSystem(() => {
|
||||
'/other.js',
|
||||
|
||||
// Because a.html changed
|
||||
'/a.js',
|
||||
'/a.js', '/module.js',
|
||||
|
||||
// b.js and module.js should not be re-emitted, because specifically when tracking
|
||||
// resource dependencies, the compiler knows that a change to a resource file only affects
|
||||
|
@ -160,7 +160,7 @@ runInEachFileSystem(() => {
|
||||
expect(written).toContain('/bar_directive.js');
|
||||
expect(written).toContain('/bar_component.js');
|
||||
expect(written).toContain('/bar_module.js');
|
||||
expect(written).not.toContain('/foo_component.js');
|
||||
expect(written).toContain('/foo_component.js');
|
||||
expect(written).not.toContain('/foo_pipe.js');
|
||||
expect(written).not.toContain('/foo_module.js');
|
||||
});
|
||||
@ -251,7 +251,7 @@ runInEachFileSystem(() => {
|
||||
expect(written).toContain('/foo_module.js');
|
||||
});
|
||||
|
||||
it('should rebuild only a Component (but with the correct CompilationScope) if its template has changed',
|
||||
it('should rebuild only a Component (but with the correct CompilationScope) and its module if its template has changed',
|
||||
() => {
|
||||
setupFooBarProgram(env);
|
||||
|
||||
@ -262,7 +262,9 @@ runInEachFileSystem(() => {
|
||||
const written = env.getFilesWrittenSinceLastFlush();
|
||||
expect(written).not.toContain('/bar_directive.js');
|
||||
expect(written).toContain('/bar_component.js');
|
||||
expect(written).not.toContain('/bar_module.js');
|
||||
// /bar_module.js should also be re-emitted, because remote scoping of BarComponent might
|
||||
// have been affected.
|
||||
expect(written).toContain('/bar_module.js');
|
||||
expect(written).not.toContain('/foo_component.js');
|
||||
expect(written).not.toContain('/foo_pipe.js');
|
||||
expect(written).not.toContain('/foo_module.js');
|
||||
|
Reference in New Issue
Block a user