From ec0ce6005a26779e7e7c1f65ac373ebf02da1efe Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Thu, 9 Apr 2020 14:56:28 +0100 Subject: [PATCH] perf(ngcc): reduce the size of the entry-point manifest file (#36486) The base path for package and entry-points is known so there is no need to store these in the file. Also this commit avoids storing empty arrays unnecessarily. PR Close #36486 --- .../ngcc/src/packages/entry_point_manifest.ts | 56 +++++++++++++------ .../ngcc/test/integration/ngcc_spec.ts | 10 ++-- .../packages/entry_point_manifest_spec.ts | 10 ++-- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts b/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts index 30dbf4f255..9321ad5940 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts @@ -69,10 +69,12 @@ export class EntryPointManifest { const startTime = Date.now(); const entryPoints: EntryPointWithDependencies[] = []; - for (const [packagePath, entryPointPath, dependencyPaths, missingPaths, deepImportPaths] of - entryPointPaths) { - const result = - getEntryPointInfo(this.fs, this.config, this.logger, packagePath, entryPointPath); + for (const + [packagePath, entryPointPath, dependencyPaths = [], missingPaths = [], + deepImportPaths = []] of entryPointPaths) { + const result = getEntryPointInfo( + this.fs, this.config, this.logger, this.fs.resolve(basePath, packagePath), + this.fs.resolve(basePath, entryPointPath)); if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) { throw new Error(`The entry-point manifest at ${ manifestPath} contained an invalid pair of package paths: [${packagePath}, ${ @@ -122,14 +124,27 @@ export class EntryPointManifest { ngccVersion: NGCC_VERSION, configFileHash: this.config.hash, lockFileHash: lockFileHash, - entryPointPaths: entryPoints.map( - e => - [e.entryPoint.package, - e.entryPoint.path, - Array.from(e.depInfo.dependencies), - Array.from(e.depInfo.missing), - Array.from(e.depInfo.deepImports), - ]), + entryPointPaths: entryPoints.map(e => { + const entryPointPaths: EntryPointPaths = [ + this.fs.relative(basePath, e.entryPoint.package), + this.fs.relative(basePath, e.entryPoint.path), + ]; + // Only add depInfo arrays if needed. + if (e.depInfo.dependencies.size > 0) { + entryPointPaths[2] = Array.from(e.depInfo.dependencies); + } else if (e.depInfo.missing.size > 0 || e.depInfo.deepImports.size > 0) { + entryPointPaths[2] = []; + } + if (e.depInfo.missing.size > 0) { + entryPointPaths[3] = Array.from(e.depInfo.missing); + } else if (e.depInfo.deepImports.size > 0) { + entryPointPaths[3] = []; + } + if (e.depInfo.deepImports.size > 0) { + entryPointPaths[4] = Array.from(e.depInfo.deepImports); + } + return entryPointPaths; + }), }; this.fs.writeFile(this.getEntryPointManifestPath(basePath), JSON.stringify(manifest)); } @@ -156,8 +171,8 @@ export class EntryPointManifest { * current manifest file. * * It always returns `null` from the `readEntryPointsUsingManifest()` method, which forces a new - * manifest to be created, which will overwrite the current file when `writeEntryPointManifest()` is - * called. + * manifest to be created, which will overwrite the current file when `writeEntryPointManifest()` + * is called. */ export class InvalidatingEntryPointManifest extends EntryPointManifest { readEntryPointsUsingManifest(_basePath: AbsoluteFsPath): EntryPointWithDependencies[]|null { @@ -165,6 +180,14 @@ export class InvalidatingEntryPointManifest extends EntryPointManifest { } } +export type EntryPointPaths = [ + string, + string, + Array?, + Array?, + Array?, +]; + /** * The JSON format of the manifest file that is written to disk. */ @@ -172,8 +195,5 @@ export interface EntryPointManifestFile { ngccVersion: string; configFileHash: string; lockFileHash: string; - entryPointPaths: Array<[ - AbsoluteFsPath, AbsoluteFsPath, AbsoluteFsPath[], (AbsoluteFsPath | PathSegment)[], - AbsoluteFsPath[] - ]>; + entryPointPaths: EntryPointPaths[]; } diff --git a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts index e9a8d26e6e..a4c6ae2d31 100644 --- a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts +++ b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts @@ -1079,7 +1079,7 @@ runInEachFileSystem(() => { // Populate the manifest file mainNgcc( {basePath: '/node_modules', propertiesToConsider: ['esm5'], logger: new MockLogger()}); - // Check that common/testings ES5 was processed + // Check that common/testing ES5 was processed let commonTesting = JSON.parse(fs.readFile(_('/node_modules/@angular/common/testing/package.json'))); expect(hasBeenProcessed(commonTesting, 'esm5')).toBe(true); @@ -1087,8 +1087,8 @@ runInEachFileSystem(() => { // Modify the manifest to test that is has no effect let manifest: EntryPointManifestFile = JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json'))); - manifest.entryPointPaths = manifest.entryPointPaths.filter( - paths => paths[1] !== _('/node_modules/@angular/common/testing')); + manifest.entryPointPaths = + manifest.entryPointPaths.filter(paths => paths[1] !== '@angular/common/testing'); fs.writeFile(_('/node_modules/__ngcc_entry_points__.json'), JSON.stringify(manifest)); // Now run ngcc again ignoring this manifest but trying to process ES2015, which are not yet // processed. @@ -1107,12 +1107,12 @@ runInEachFileSystem(() => { // had removed earlier. manifest = JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json'))); expect(manifest.entryPointPaths).toContain([ - _('/node_modules/@angular/common'), _('/node_modules/@angular/common/testing'), + '@angular/common', + '@angular/common/testing', [ _('/node_modules/@angular/core'), _('/node_modules/@angular/common'), _('/node_modules/rxjs') ], - [], [] ]); }); }); diff --git a/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts b/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts index 968b0eb1f2..afed5fe6b1 100644 --- a/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts @@ -284,18 +284,16 @@ runInEachFileSystem(() => { JSON.parse(fs.readFile(_Abs('/project/node_modules/__ngcc_entry_points__.json'))); expect(file.entryPointPaths).toEqual([ [ - _Abs('/project/node_modules/package-1/'), - _Abs('/project/node_modules/package-1/'), + 'package-1', + 'package-1', [ _Abs('/project/node_modules/other_package_1'), _Abs('/project/node_modules/other_package_2'), ], - [], - [], ], [ - _Abs('/project/node_modules/package-2/'), - _Abs('/project/node_modules/package-2/entry-point'), + 'package-2', + 'package-2/entry-point', [], [ _Abs('/project/node_modules/missing_1'),