Skip to content

Commit 3deb68f

Browse files
committed
perf(@angular/build): avoid loading compiler-cli and typescript in js transform worker
Previously, `OxcLinker` imported `ConsoleLogger` and `LogLevel` directly from `@angular/compiler-cli`. Even though `@angular/compiler-cli/linker` is an isolated, lightweight runtime (depending only on `semver` and `convert-source-map`), resolving the main `@angular/compiler-cli` entry point (`bundles/index.js`) eagerly evaluated the full `ngtsc` compiler toolchain and required the 10 MB `typescript.js` bundle at the top level. As a result, every worker isolate in the JavaScript transformer pool unnecessarily loaded TypeScript and 50+ compiler modules upon bootstrap, incurring ~150 ms of startup CPU latency and allocating ~12 MB of heap per worker thread.
1 parent eb2ba36 commit 3deb68f

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

‎packages/angular/build/src/tools/angular/linker/oxc-linker.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { ConsoleLogger, LogLevel } from '@angular/compiler-cli';
9+
import type { Logger } from '@angular/compiler-cli';
1010
import { type DeclarationScope, FileLinker, LinkerEnvironment } from '@angular/compiler-cli/linker';
1111
import type {
1212
AbsoluteFsPath,
@@ -45,7 +45,23 @@ const noopFileSystem: ReadonlyFileSystem = {
4545
relative: (_from: string, to: string) => to,
4646
} as unknown as ReadonlyFileSystem;
4747

48-
let SHARED_LOGGER: ConsoleLogger;
48+
const defaultLogger: Logger = {
49+
level: 1, // LogLevel.info
50+
debug() {},
51+
info(...args: string[]) {
52+
// eslint-disable-next-line no-console
53+
console.info(...args);
54+
},
55+
warn(...args: string[]) {
56+
// eslint-disable-next-line no-console
57+
console.warn(...args);
58+
},
59+
error(...args: string[]) {
60+
// eslint-disable-next-line no-console
61+
console.error(...args);
62+
},
63+
};
64+
4965
let SHARED_AST_HOST: OxcAstHost;
5066
let SHARED_DECLARATION_SCOPE: InlineDeclarationScope;
5167

@@ -56,14 +72,13 @@ export class OxcLinker {
5672
readonly #fileLinker: FileLinker<unknown, string, unknown, string | undefined>;
5773

5874
constructor(filename: string, code: string, jit = false) {
59-
SHARED_LOGGER ??= new ConsoleLogger(LogLevel.info);
6075
SHARED_AST_HOST ??= new OxcAstHost();
6176
SHARED_DECLARATION_SCOPE ??= new InlineDeclarationScope();
6277

6378
const astFactory = new StringAstFactory(code);
6479
const linkerEnvironment = LinkerEnvironment.create(
6580
noopFileSystem,
66-
SHARED_LOGGER,
81+
defaultLogger,
6782
SHARED_AST_HOST,
6883
astFactory,
6984
{ linkerJitMode: jit, sourceMapping: false },

0 commit comments

Comments
 (0)