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 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<AbsoluteFsPath>?,
Array<AbsoluteFsPath|PathSegment>?,
Array<AbsoluteFsPath>?,
];
/**
* 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[];
}

View File

@ -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')
],
[], []
]);
});
});

View File

@ -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'),