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

View File

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