Navigation Menu

Skip to content

Commit

Permalink
perf(compiler): fix perf issue in loading aot summaries in jit compiler
Browse files Browse the repository at this point in the history
The current `flattenSummaries` function re-process the same NgModule
summary even if it has been processed before. Certain modules like
CommonModule are repeated multiple times in the module tree and it is
expanded out every time.

This was making unit tests using AOT summaries really slow. This will
also slow down JIT bootstrap applications that load AOT summaries for
component libraries.

The fix is to remember which summaries were seen before and not to
process them again.
  • Loading branch information
vikerman authored and alxhub committed Oct 4, 2017
1 parent f580ffa commit fbc9537
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/compiler/src/jit/compiler.ts
Expand Up @@ -335,14 +335,22 @@ function assertComponent(meta: CompileDirectiveMetadata) {
}
}

function flattenSummaries(fn: () => any[], out: CompileTypeSummary[] = []): CompileTypeSummary[] {
fn().forEach((entry) => {
function flattenSummaries(
fn: () => any[], out: CompileTypeSummary[] = [],
seen = new Set<() => any[]>()): CompileTypeSummary[] {
if (seen.has(fn)) {
return out;
}
seen.add(fn);
const summaries = fn();
for (let i = 0; i < summaries.length; i++) {
const entry = summaries[i];
if (typeof entry === 'function') {
flattenSummaries(entry, out);
flattenSummaries(entry, out, seen);
} else {
out.push(entry);
}
});
}
return out;
}

Expand Down

0 comments on commit fbc9537

Please sign in to comment.