Skip to content

Commit b2ccc34

Browse files
crisbetoatscott
authored andcommitted
perf(core): avoid pulling in jit-specific code in aot bundles (angular#37372)
In angular#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 angular#37372
1 parent eaa38a5 commit b2ccc34

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

goldens/size-tracking/aio-payloads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"master": {
1313
"uncompressed": {
1414
"runtime-es2015": 2987,
15-
"main-es2015": 453386,
15+
"main-es2015": 451918,
1616
"polyfills-es2015": 52655
1717
}
1818
}

goldens/size-tracking/integration-payloads.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"master": {
44
"uncompressed": {
55
"runtime-es2015": 1485,
6-
"main-es2015": 142590,
6+
"main-es2015": 141394,
77
"polyfills-es2015": 36963
88
}
99
}
@@ -21,7 +21,7 @@
2121
"master": {
2222
"uncompressed": {
2323
"runtime-es2015": 1485,
24-
"main-es2015": 148510,
24+
"main-es2015": 147314,
2525
"polyfills-es2015": 36963
2626
}
2727
}
@@ -30,7 +30,7 @@
3030
"master": {
3131
"uncompressed": {
3232
"runtime-es2015": 1485,
33-
"main-es2015": 138196,
33+
"main-es2015": 136873,
3434
"polyfills-es2015": 37640
3535
}
3636
}
@@ -39,7 +39,7 @@
3939
"master": {
4040
"uncompressed": {
4141
"runtime-es2015": 2289,
42-
"main-es2015": 247942,
42+
"main-es2015": 246781,
4343
"polyfills-es2015": 36657,
4444
"5-es2015": 751
4545
}
@@ -49,7 +49,7 @@
4949
"master": {
5050
"uncompressed": {
5151
"runtime-es2015": 2289,
52-
"main-es2015": 223603,
52+
"main-es2015": 221961,
5353
"polyfills-es2015": 36657,
5454
"5-es2015": 779
5555
}
@@ -61,8 +61,8 @@
6161
"bundle": "TODO(i): temporarily increase the payload size limit from 105779 - this is due to a closure issue related to ESM reexports that still needs to be investigated",
6262
"bundle": "TODO(i): we should define ngDevMode to false in Closure, but --define only works in the global scope.",
6363
"bundle": "TODO(i): (FW-2164) TS 3.9 new class shape seems to have broken Closure in big ways. The size went from 169991 to 252338",
64-
"bundle": "TODO(i): after removal of tsickle from ngc-wrapped / ng_package, we had to switch to SIMPLE optimizations which increased the size from 252338 to 1197869, see PR#37221 and PR#37317 for more info",
65-
"bundle": 1198831
64+
"bundle": "TODO(i): after removal of tsickle from ngc-wrapped / ng_package, we had to switch to SIMPLE optimizations which increased the size from 252338 to 1198917, see PR#37221 and PR#37317 for more info",
65+
"bundle": 1198917
6666
}
6767
}
6868
}

packages/core/src/application_ref.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,22 @@ export function compileNgModuleFactory__POST_R3__<M>(
6060
moduleType: Type<M>): Promise<NgModuleFactory<M>> {
6161
ngDevMode && assertNgModuleType(moduleType);
6262

63-
const compilerOptions = injector.get(COMPILER_OPTIONS, []).concat(options);
63+
const moduleFactory = new R3NgModuleFactory(moduleType);
6464

65-
if (typeof ngJitMode === 'undefined' || ngJitMode) {
66-
// Configure the compiler to use the provided options. This call may fail when multiple modules
67-
// are bootstrapped with incompatible options, as a component can only be compiled according to
68-
// a single set of options.
69-
setJitOptions({
70-
defaultEncapsulation:
71-
_lastDefined(compilerOptions.map(options => options.defaultEncapsulation)),
72-
preserveWhitespaces:
73-
_lastDefined(compilerOptions.map(options => options.preserveWhitespaces)),
74-
});
65+
// All of the logic below is irrelevant for AOT-compiled code.
66+
if (typeof ngJitMode !== 'undefined' && !ngJitMode) {
67+
return Promise.resolve(moduleFactory);
7568
}
7669

77-
const moduleFactory = new R3NgModuleFactory(moduleType);
70+
const compilerOptions = injector.get(COMPILER_OPTIONS, []).concat(options);
71+
72+
// Configure the compiler to use the provided options. This call may fail when multiple modules
73+
// are bootstrapped with incompatible options, as a component can only be compiled according to
74+
// a single set of options.
75+
setJitOptions({
76+
defaultEncapsulation: _lastDefined(compilerOptions.map(opts => opts.defaultEncapsulation)),
77+
preserveWhitespaces: _lastDefined(compilerOptions.map(opts => opts.preserveWhitespaces)),
78+
});
7879

7980
if (isComponentResourceResolutionQueueEmpty()) {
8081
return Promise.resolve(moduleFactory);

0 commit comments

Comments
 (0)