Skip to content

perf(@angular/build): optimize library dts bundling and enable dts tree-shaking - #34431

Open
alan-agius4 wants to merge 5 commits into
angular:mainfrom
alan-agius4:perf/library-bundler-dts-and-rolldown
Open

alan-agius4 wants to merge 5 commits into
angular:mainfrom
alan-agius4:perf/library-bundler-dts-and-rolldown

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Enable .d.ts tree-shaking: Set treeshake: isDts ? { moduleSideEffects: false } : false in executeMultiBundle to strip unexported internal types and unused namespace declarations from .d.ts bundles.
  • Bypass dts() wrapper in bundleAllDts: Cache the import('rolldown-plugin-dts') promise at module scope and invoke createFakeJsPlugin directly instead of calling dts({ dtsInput: true, ... }) and filtering out rolldown-plugin-dts:resolver. This avoids unconditionally instantiating a native oxc-resolver (ResolverFactory) on every build.
  • Disable Rolldown tsconfig auto-discovery and plugin timings: Pass tsconfig: false and checks: { circularDependency: false, pluginTimings: false } to rolldown() in executeMultiBundle.

Benchmark

Metric main Branch Delta
Runs (ms) 12086, 11842, 12025, 12057, 11634 11947, 11726, 11606, 11760, 11868
Median (ms) 12025 ms 11760 ms -2.20%
Mean (ms) 11929 ms 11781 ms -1.24%
Min (ms) 11634 ms 11606 ms -0.24%

…ee-shaking

- Enable tree-shaking (`{ moduleSideEffects: false }`) for `.d.ts` bundles in `executeMultiBundle` so unexported internal types and unused namespace declarations are stripped, and skip emitting empty or virtual-only `rolldown-runtime` non-entry `.d.ts` chunks in `processRolldownOutput`.
- Cache the `rolldown-plugin-dts` module import promise and invoke `createFakeJsPlugin` directly in `bundleAllDts` instead of calling `dts({ dtsInput: true, ... })`, eliminating redundant per-build `oxc-resolver` (`ResolverFactory`) instantiation.
- Disable Rolldown `tsconfig` auto-discovery (`tsconfig: false`) and plugin timing instrumentation (`checks: { circularDependency: false, pluginTimings: false }`) in `executeMultiBundle`.
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Oct 20, 2026
@alan-agius4
alan-agius4 requested a review from clydin October 20, 2026 10:33
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Oct 20, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review October 20, 2026 10:34

@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 the library bundler pipeline by dynamically loading rolldown-plugin-dts and directly instantiating createFakeJsPlugin to avoid unnecessary native resolver instantiation. It also introduces logic to skip empty or virtual-only .d.ts chunks (such as rolldown-runtime helpers) and adds corresponding unit and integration tests. Feedback was provided to ensure that skipped .d.ts chunks are not actively imported by other chunks, which could otherwise lead to broken import references. A code suggestion was provided to track and exclude imported files from being skipped.

Comment thread packages/angular/build/src/builders/library/pipeline/bundler.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build area: performance Issues related to performance target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant