Skip to content

Commit 603b094

Browse files
petebacondarwinatscott
authored andcommitted
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
1 parent 918e628 commit 603b094

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

packages/compiler-cli/ngcc/src/packages/entry_point_manifest.ts

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ export class EntryPointManifest {
6969
const startTime = Date.now();
7070

7171
const entryPoints: EntryPointWithDependencies[] = [];
72-
for (const [packagePath, entryPointPath, dependencyPaths, missingPaths, deepImportPaths] of
73-
entryPointPaths) {
74-
const result =
75-
getEntryPointInfo(this.fs, this.config, this.logger, packagePath, entryPointPath);
72+
for (const
73+
[packagePath, entryPointPath, dependencyPaths = [], missingPaths = [],
74+
deepImportPaths = []] of entryPointPaths) {
75+
const result = getEntryPointInfo(
76+
this.fs, this.config, this.logger, this.fs.resolve(basePath, packagePath),
77+
this.fs.resolve(basePath, entryPointPath));
7678
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
7779
throw new Error(`The entry-point manifest at ${
7880
manifestPath} contained an invalid pair of package paths: [${packagePath}, ${
@@ -122,14 +124,27 @@ export class EntryPointManifest {
122124
ngccVersion: NGCC_VERSION,
123125
configFileHash: this.config.hash,
124126
lockFileHash: lockFileHash,
125-
entryPointPaths: entryPoints.map(
126-
e =>
127-
[e.entryPoint.package,
128-
e.entryPoint.path,
129-
Array.from(e.depInfo.dependencies),
130-
Array.from(e.depInfo.missing),
131-
Array.from(e.depInfo.deepImports),
132-
]),
127+
entryPointPaths: entryPoints.map(e => {
128+
const entryPointPaths: EntryPointPaths = [
129+
this.fs.relative(basePath, e.entryPoint.package),
130+
this.fs.relative(basePath, e.entryPoint.path),
131+
];
132+
// Only add depInfo arrays if needed.
133+
if (e.depInfo.dependencies.size > 0) {
134+
entryPointPaths[2] = Array.from(e.depInfo.dependencies);
135+
} else if (e.depInfo.missing.size > 0 || e.depInfo.deepImports.size > 0) {
136+
entryPointPaths[2] = [];
137+
}
138+
if (e.depInfo.missing.size > 0) {
139+
entryPointPaths[3] = Array.from(e.depInfo.missing);
140+
} else if (e.depInfo.deepImports.size > 0) {
141+
entryPointPaths[3] = [];
142+
}
143+
if (e.depInfo.deepImports.size > 0) {
144+
entryPointPaths[4] = Array.from(e.depInfo.deepImports);
145+
}
146+
return entryPointPaths;
147+
}),
133148
};
134149
this.fs.writeFile(this.getEntryPointManifestPath(basePath), JSON.stringify(manifest));
135150
}
@@ -156,24 +171,29 @@ export class EntryPointManifest {
156171
* current manifest file.
157172
*
158173
* It always returns `null` from the `readEntryPointsUsingManifest()` method, which forces a new
159-
* manifest to be created, which will overwrite the current file when `writeEntryPointManifest()` is
160-
* called.
174+
* manifest to be created, which will overwrite the current file when `writeEntryPointManifest()`
175+
* is called.
161176
*/
162177
export class InvalidatingEntryPointManifest extends EntryPointManifest {
163178
readEntryPointsUsingManifest(_basePath: AbsoluteFsPath): EntryPointWithDependencies[]|null {
164179
return null;
165180
}
166181
}
167182

183+
export type EntryPointPaths = [
184+
string,
185+
string,
186+
Array<AbsoluteFsPath>?,
187+
Array<AbsoluteFsPath|PathSegment>?,
188+
Array<AbsoluteFsPath>?,
189+
];
190+
168191
/**
169192
* The JSON format of the manifest file that is written to disk.
170193
*/
171194
export interface EntryPointManifestFile {
172195
ngccVersion: string;
173196
configFileHash: string;
174197
lockFileHash: string;
175-
entryPointPaths: Array<[
176-
AbsoluteFsPath, AbsoluteFsPath, AbsoluteFsPath[], (AbsoluteFsPath | PathSegment)[],
177-
AbsoluteFsPath[]
178-
]>;
198+
entryPointPaths: EntryPointPaths[];
179199
}

packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,16 +1079,16 @@ runInEachFileSystem(() => {
10791079
// Populate the manifest file
10801080
mainNgcc(
10811081
{basePath: '/node_modules', propertiesToConsider: ['esm5'], logger: new MockLogger()});
1082-
// Check that common/testings ES5 was processed
1082+
// Check that common/testing ES5 was processed
10831083
let commonTesting =
10841084
JSON.parse(fs.readFile(_('/node_modules/@angular/common/testing/package.json')));
10851085
expect(hasBeenProcessed(commonTesting, 'esm5')).toBe(true);
10861086
expect(hasBeenProcessed(commonTesting, 'esm2015')).toBe(false);
10871087
// Modify the manifest to test that is has no effect
10881088
let manifest: EntryPointManifestFile =
10891089
JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json')));
1090-
manifest.entryPointPaths = manifest.entryPointPaths.filter(
1091-
paths => paths[1] !== _('/node_modules/@angular/common/testing'));
1090+
manifest.entryPointPaths =
1091+
manifest.entryPointPaths.filter(paths => paths[1] !== '@angular/common/testing');
10921092
fs.writeFile(_('/node_modules/__ngcc_entry_points__.json'), JSON.stringify(manifest));
10931093
// Now run ngcc again ignoring this manifest but trying to process ES2015, which are not yet
10941094
// processed.
@@ -1107,12 +1107,12 @@ runInEachFileSystem(() => {
11071107
// had removed earlier.
11081108
manifest = JSON.parse(fs.readFile(_('/node_modules/__ngcc_entry_points__.json')));
11091109
expect(manifest.entryPointPaths).toContain([
1110-
_('/node_modules/@angular/common'), _('/node_modules/@angular/common/testing'),
1110+
'@angular/common',
1111+
'@angular/common/testing',
11111112
[
11121113
_('/node_modules/@angular/core'), _('/node_modules/@angular/common'),
11131114
_('/node_modules/rxjs')
11141115
],
1115-
[], []
11161116
]);
11171117
});
11181118
});

packages/compiler-cli/ngcc/test/packages/entry_point_manifest_spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,16 @@ runInEachFileSystem(() => {
284284
JSON.parse(fs.readFile(_Abs('/project/node_modules/__ngcc_entry_points__.json')));
285285
expect(file.entryPointPaths).toEqual([
286286
[
287-
_Abs('/project/node_modules/package-1/'),
288-
_Abs('/project/node_modules/package-1/'),
287+
'package-1',
288+
'package-1',
289289
[
290290
_Abs('/project/node_modules/other_package_1'),
291291
_Abs('/project/node_modules/other_package_2'),
292292
],
293-
[],
294-
[],
295293
],
296294
[
297-
_Abs('/project/node_modules/package-2/'),
298-
_Abs('/project/node_modules/package-2/entry-point'),
295+
'package-2',
296+
'package-2/entry-point',
299297
[],
300298
[
301299
_Abs('/project/node_modules/missing_1'),

0 commit comments

Comments
 (0)