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.
This commit is contained in:
Vikram Subramanian 2017-10-04 01:53:39 -07:00 committed by Alex Rickabaugh
parent f580ffab4f
commit fbc9537952
1 changed files with 12 additions and 4 deletions

View File

@ -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;
}