perf(core): avoid pulling in jit-specific code in aot bundles (#37372)

In #29083 a call to `getCompilerFacade` was added to `ApplicationRef` which pulls in a bit of JIT-specific code. Since the code path that calls the function can't be hit for an AOT-compiled app, these changes add an `ngJitMode` guard which will allow for dead code elimination to drop it completely. Testing it out against a new CLI project showed a difference of ~1.2kb.

PR Close #37372
This commit is contained in:
crisbeto
2020-06-09 17:40:00 +02:00
committed by atscott
parent eaa38a5adc
commit b2ccc34f9c
3 changed files with 21 additions and 20 deletions

View File

@ -60,21 +60,22 @@ export function compileNgModuleFactory__POST_R3__<M>(
moduleType: Type<M>): Promise<NgModuleFactory<M>> {
ngDevMode && assertNgModuleType(moduleType);
const compilerOptions = injector.get(COMPILER_OPTIONS, []).concat(options);
const moduleFactory = new R3NgModuleFactory(moduleType);
if (typeof ngJitMode === 'undefined' || ngJitMode) {
// Configure the compiler to use the provided options. This call may fail when multiple modules
// are bootstrapped with incompatible options, as a component can only be compiled according to
// a single set of options.
setJitOptions({
defaultEncapsulation:
_lastDefined(compilerOptions.map(options => options.defaultEncapsulation)),
preserveWhitespaces:
_lastDefined(compilerOptions.map(options => options.preserveWhitespaces)),
});
// All of the logic below is irrelevant for AOT-compiled code.
if (typeof ngJitMode !== 'undefined' && !ngJitMode) {
return Promise.resolve(moduleFactory);
}
const moduleFactory = new R3NgModuleFactory(moduleType);
const compilerOptions = injector.get(COMPILER_OPTIONS, []).concat(options);
// Configure the compiler to use the provided options. This call may fail when multiple modules
// are bootstrapped with incompatible options, as a component can only be compiled according to
// a single set of options.
setJitOptions({
defaultEncapsulation: _lastDefined(compilerOptions.map(opts => opts.defaultEncapsulation)),
preserveWhitespaces: _lastDefined(compilerOptions.map(opts => opts.preserveWhitespaces)),
});
if (isComponentResourceResolutionQueueEmpty()) {
return Promise.resolve(moduleFactory);