perf(ivy): R3TestBed - Do not process NgModuleDefs that have already been processed (#33863)

PR Close #33863
This commit is contained in:
Andrew Scott 2019-11-15 13:01:50 -08:00 committed by Alex Rickabaugh
parent e13aa65f49
commit 5af3bd4728
1 changed files with 22 additions and 10 deletions

View File

@ -486,17 +486,29 @@ export class R3TestBedCompiler {
}
private queueTypesFromModulesArray(arr: any[]): void {
for (const value of arr) {
if (Array.isArray(value)) {
this.queueTypesFromModulesArray(value);
} else if (hasNgModuleDef(value)) {
const def = value.ɵmod;
// Look through declarations, imports, and exports, and queue everything found there.
this.queueTypeArray(maybeUnwrapFn(def.declarations), value);
this.queueTypesFromModulesArray(maybeUnwrapFn(def.imports));
this.queueTypesFromModulesArray(maybeUnwrapFn(def.exports));
// Because we may encounter the same NgModule while processing the imports and exports of an
// NgModule tree, we cache them in this set so we can skip ones that have already been seen
// encountered. In some test setups, this caching resulted in 10X runtime improvement.
const processedNgModuleDefs = new Set();
const queueTypesFromModulesArrayRecur = (arr: any[]): void => {
for (const value of arr) {
if (Array.isArray(value)) {
queueTypesFromModulesArrayRecur(value);
} else if (hasNgModuleDef(value)) {
const def = value.ɵmod;
if (processedNgModuleDefs.has(def)) {
continue;
}
processedNgModuleDefs.add(def);
// Look through declarations, imports, and exports, and queue
// everything found there.
this.queueTypeArray(maybeUnwrapFn(def.declarations), value);
queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.imports));
queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.exports));
}
}
}
};
queueTypesFromModulesArrayRecur(arr);
}
private maybeStoreNgDef(prop: string, type: Type<any>) {