Skip to content

perf(@angular/cli): avoid eager module loading during global bootstrap - #33811

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:perf/lazy-load-bootstrap-warning
Aug 7, 2026
Merged

perf(@angular/cli): avoid eager module loading during global bootstrap#33811
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:perf/lazy-load-bootstrap-warning

Conversation

@clydin

@clydin clydin commented Aug 7, 2026

Copy link
Copy Markdown
Member

Avoid importing isWarningEnabled and colors statically in init.ts. Eagerly importing config.ts causes @angular-devkit/core and its transitive dependencies (rxjs, ajv, jsonc-parser, and schema registries) to be evaluated synchronously in the global CLI context before resolving the project local CLI.

By lazily importing config.ts and color.ts only when isGlobalGreater is true and a version mismatch warning needs to be issued, cold CLI invocations avoid evaluating these packages globally during bootstrap.

@clydin clydin added the target: patch This PR is targeted for the next patch release label Aug 7, 2026
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/cli labels Aug 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes startup performance in the Angular CLI initialization by refactoring the static imports of colors and isWarningEnabled into dynamic imports that are only loaded when a version mismatch warning is triggered. The review feedback highlights a potential issue where an error during these dynamic imports or the warning check could cause the outer try-catch block to silently fall back to the global CLI instead of using the local CLI. It is recommended to wrap this non-critical warning logic in its own try-catch block to prevent such failures from affecting the CLI execution flow.

Comment thread packages/angular/cli/lib/init.ts
Avoid importing `isWarningEnabled` and `colors` statically in `init.ts`.
Eagerly importing `config.ts` causes `@angular-devkit/core` and its transitive
dependencies (`rxjs`, `ajv`, `jsonc-parser`, and schema registries) to be
evaluated synchronously in the global CLI context before resolving the project
local CLI.

By lazily importing `config.ts` and `color.ts` only when `isGlobalGreater` is
true and a version mismatch warning needs to be issued, cold CLI invocations
avoid evaluating these packages globally during bootstrap.
@clydin
clydin force-pushed the perf/lazy-load-bootstrap-warning branch from 432302f to debafb5 Compare August 7, 2026 17:46
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 7, 2026
@clydin
clydin requested a review from alan-agius4 August 7, 2026 18:06
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 7, 2026
@alan-agius4
alan-agius4 merged commit 2e4dd90 into angular:main Aug 7, 2026
41 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

@clydin
clydin deleted the perf/lazy-load-bootstrap-warning branch August 7, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli area: performance Issues related to performance target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants