Skip to content

perf(@angular/build): avoid reading external component stylesheets twice - #34434

Merged
alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:perf/skip-double-stylesheet-read
Oct 21, 2026
Merged

alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:perf/skip-double-stylesheet-read

Conversation

@alan-agius4

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

Copy link
Copy Markdown
Collaborator
  • In host.readResource(filename), return '' directly when !hasTemplateExtension(filename) instead of reading the external stylesheet file from disk on the Angular compiler worker thread and serializing its contents over the worker MessagePort, since transformStylesheet ignores data when stylesheetFile is provided and reads/bundles the file via stylesheetBundler.bundleFile(stylesheetFile).
  • In host.transformResource(data, context), only short-circuit empty data for inline styles (!context.resourceFile && data.trim().length === 0) so external stylesheets proceed to hostOptions.transformStylesheet.

- Skip calling `this.readFile(filename)` in `host.readResource(filename)` when `!hasTemplateExtension(filename)` so external component stylesheets (`styleUrl` / `styleUrls`) are not read from disk on the Angular compiler worker thread and serialized over the worker `MessagePort` only to be ignored by `transformStylesheet`.
- Only short-circuit empty `data` in `host.transformResource(data, context)` for inline styles (`!context.resourceFile`) so external stylesheets still proceed to `transformStylesheet`.
@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:25
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 20, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review October 21, 2026 06:44

@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 resource loading and transformation in the Angular compiler host. Specifically, readResource is updated to only read template files, bypassing external stylesheets which are bundled during transformResource. Additionally, transformResource is adjusted to only short-circuit empty inline styles, ensuring empty external stylesheets are still processed. Unit tests have been added to verify these changes. As there are no review comments, I have no feedback to provide.

@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Oct 21, 2026
@alan-agius4
alan-agius4 merged commit 5691298 into angular:main Oct 21, 2026
41 checks passed
@alan-agius4
alan-agius4 deleted the perf/skip-double-stylesheet-read branch October 21, 2026 15:42
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

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

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 action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build 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