Permalink
Browse files

perf(compiler): fix perf issue in loading aot summaries in jit compiler

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 fbc9537952622645a4a45ce28ec90956c85922f9
Showing with 12 additions and 4 deletions.
  1. +12 −4 packages/compiler/src/jit/compiler.ts
@@ -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;
}

0 comments on commit fbc9537

Please sign in to comment.