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
This commit is contained in:
Pete Bacon Darwin 2020-04-09 14:56:28 +01:00 committed by atscott
parent a185efbd60
commit ec0ce6005a
3 changed files with 47 additions and 29 deletions

View File

@ -69,10 +69,12 @@ export class EntryPointManifest {
const startTime = Date.now(); const startTime = Date.now();
const entryPoints: EntryPointWithDependencies[] = []; const entryPoints: EntryPointWithDependencies[] = [];
for (const [packagePath, entryPointPath, dependencyPaths, missingPaths, deepImportPaths] of for (const
entryPointPaths) { [packagePath, entryPointPath, dependencyPaths = [], missingPaths = [],
const result = deepImportPaths = []] of entryPointPaths) {
getEntryPointInfo(this.fs, this.config, this.logger, packagePath, entryPointPath); 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) { if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
throw new Error(`The entry-point manifest at ${ throw new Error(`The entry-point manifest at ${
manifestPath} contained an invalid pair of package paths: [${packagePath}, ${ manifestPath} contained an invalid pair of package paths: [${packagePath}, ${
@ -122,14 +124,27 @@ export class EntryPointManifest {
ngccVersion: NGCC_VERSION, ngccVersion: NGCC_VERSION,
configFileHash: this.config.hash, configFileHash: this.config.hash,
lockFileHash: lockFileHash, lockFileHash: lockFileHash,
entryPointPaths: entryPoints.map( entryPointPaths: entryPoints.map(e => {
e => const entryPointPaths: EntryPointPaths = [
[e.entryPoint.package, this.fs.relative(basePath, e.entryPoint.package),
e.entryPoint.path, this.fs.relative(basePath, e.entryPoint.path),
Array.from(e.depInfo.dependencies), ];
Array.from(e.depInfo.missing), // Only add depInfo arrays if needed.
Array.from(e.depInfo.deepImports), 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)); this.fs.writeFile(this.getEntryPointManifestPath(basePath), JSON.stringify(manifest));
} }
@ -156,8 +171,8 @@ export class EntryPointManifest {
* current manifest file. * current manifest file.
* *
* It always returns `null` from the `readEntryPointsUsingManifest()` method, which forces a new * 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 * manifest to be created, which will overwrite the current file when `writeEntryPointManifest()`
* called. * is called.
*/ */
export class InvalidatingEntryPointManifest extends EntryPointManifest { export class InvalidatingEntryPointManifest extends EntryPointManifest {
readEntryPointsUsingManifest(_basePath: AbsoluteFsPath): EntryPointWithDependencies[]|null { readEntryPointsUsingManifest(_basePath: AbsoluteFsPath): EntryPointWithDependencies[]|null {
@ -165,6 +180,14 @@ export class InvalidatingEntryPointManifest extends EntryPointManifest {
} }
} }
export type EntryPointPaths = [
string,
string,
Array<AbsoluteFsPath>?,
Array<AbsoluteFsPath|PathSegment>?,
Array<AbsoluteFsPath>?,
];
/** /**
* The JSON format of the manifest file that is written to disk. * The JSON format of the manifest file that is written to disk.
*/ */
@ -172,8 +195,5 @@ export interface EntryPointManifestFile {
ngccVersion: string; ngccVersion: string;
configFileHash: string; configFileHash: string;
lockFileHash: string; lockFileHash: string;
entryPointPaths: Array<[ entryPointPaths: EntryPointPaths[];
AbsoluteFsPath, AbsoluteFsPath, AbsoluteFsPath[], (AbsoluteFsPath | PathSegment)[],
AbsoluteFsPath[]
]>;
} }

View File

@ -1079,7 +1079,7 @@ runInEachFileSystem(() => {
// Populate the manifest file // Populate the manifest file
mainNgcc( mainNgcc(
{basePath: '/node_modules', propertiesToConsider: ['esm5'], logger: new MockLogger()}); {basePath: '/node_modules', propertiesToConsider: ['esm5'], logger: new MockLogger()});
// Check that common/testings ES5 was processed // Check that common/testing ES5 was processed
let commonTesting = let commonTesting =
JSON.parse(fs.readFile(_('/node_modules/@angular/common/testing/package.json'))); JSON.parse(fs.readFile(_('/node_modules/@angular/common/testing/package.json')));
expect(hasBeenProcessed(commonTesting, 'esm5')).toBe(true); expect(hasBeenProcessed(commonTesting, 'esm5')).toBe(true);
@ -1087,8 +1087,8 @@ runInEachFileSystem(() => {
// Modify the manifest to test that is has no effect // Modify the manifest to test that is has no effect
let manifest: EntryPointManifestFile = let manifest: EntryPointManifestFile =
JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json'))); JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json')));
manifest.entryPointPaths = manifest.entryPointPaths.filter( manifest.entryPointPaths =
paths => paths[1] !== _('/node_modules/@angular/common/testing')); manifest.entryPointPaths.filter(paths => paths[1] !== '@angular/common/testing');
fs.writeFile(_('/node_modules/__ngcc_entry_points__.json'), JSON.stringify(manifest)); 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 // Now run ngcc again ignoring this manifest but trying to process ES2015, which are not yet
// processed. // processed.
@ -1107,12 +1107,12 @@ runInEachFileSystem(() => {
// had removed earlier. // had removed earlier.
manifest = JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json'))); manifest = JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json')));
expect(manifest.entryPointPaths).toContain([ 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/@angular/core'), _('/node_modules/@angular/common'),
_('/node_modules/rxjs') _('/node_modules/rxjs')
], ],
[], []
]); ]);
}); });
}); });

View File

@ -284,18 +284,16 @@ runInEachFileSystem(() => {
JSON.parse(fs.readFile(_Abs('/project/node_modules/__ngcc_entry_points__.json'))); JSON.parse(fs.readFile(_Abs('/project/node_modules/__ngcc_entry_points__.json')));
expect(file.entryPointPaths).toEqual([ expect(file.entryPointPaths).toEqual([
[ [
_Abs('/project/node_modules/package-1/'), 'package-1',
_Abs('/project/node_modules/package-1/'), 'package-1',
[ [
_Abs('/project/node_modules/other_package_1'), _Abs('/project/node_modules/other_package_1'),
_Abs('/project/node_modules/other_package_2'), _Abs('/project/node_modules/other_package_2'),
], ],
[],
[],
], ],
[ [
_Abs('/project/node_modules/package-2/'), 'package-2',
_Abs('/project/node_modules/package-2/entry-point'), 'package-2/entry-point',
[], [],
[ [
_Abs('/project/node_modules/missing_1'), _Abs('/project/node_modules/missing_1'),