perf(ngcc): cache parsed tsconfig between runs (#37417)

This commit will store a cached copy of the parsed tsconfig
that can be reused if the tsconfig path is the same.

This will improve the ngcc "noop" case, where there is no processing
to do, when the entry-points have already been processed.
Previously we were parsing this config every time we checked for
entry-points to process, which can take up to seconds in some
cases.

Resolves #36882

PR Close #37417
This commit is contained in:
Pete Bacon Darwin
2020-06-03 17:18:46 +01:00
committed by atscott
parent 2021ad12cf
commit 6e7bd939f6
4 changed files with 110 additions and 2 deletions

View File

@ -156,7 +156,7 @@ export function getSharedSetup(options: NgccOptions): SharedSetup&RequiredNgccOp
const absBasePath = absoluteFrom(options.basePath);
const projectPath = fileSystem.dirname(absBasePath);
const tsConfig =
options.tsConfigPath !== null ? readConfiguration(options.tsConfigPath || projectPath) : null;
options.tsConfigPath !== null ? getTsConfig(options.tsConfigPath || projectPath) : null;
let {
basePath,
@ -200,3 +200,28 @@ export function getSharedSetup(options: NgccOptions): SharedSetup&RequiredNgccOp
new InPlaceFileWriter(fileSystem, logger, errorOnFailedEntryPoint),
};
}
let tsConfigCache: ParsedConfiguration|null = null;
let tsConfigPathCache: string|null = null;
/**
* Get the parsed configuration object for the given `tsConfigPath`.
*
* This function will cache the previous parsed configuration object to avoid unnecessary processing
* of the tsconfig.json in the case that it is requested repeatedly.
*
* This makes the assumption, which is true as of writing, that the contents of tsconfig.json and
* its dependencies will not change during the life of the process running ngcc.
*/
function getTsConfig(tsConfigPath: string): ParsedConfiguration|null {
if (tsConfigPath !== tsConfigPathCache) {
tsConfigPathCache = tsConfigPath;
tsConfigCache = readConfiguration(tsConfigPath);
}
return tsConfigCache;
}
export function clearTsConfigCache() {
tsConfigPathCache = null;
tsConfigCache = null;
}