Skip to content

perf(@angular/build): batch prerender routes and share in-memory server bundles - #33905

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:perf-prerender-route-batching-shared-bundles
Aug 25, 2026
Merged

perf(@angular/build): batch prerender routes and share in-memory server bundles#33905
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:perf-prerender-route-batching-shared-bundles

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Performance improvement
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

  1. In-memory server bundles and manifests are passed in workerData as strings, causing V8 structuredClone serialization to copy all bundles into every worker thread isolate and ESM loader hook instance.
  2. In prerender.ts, renderPages dispatches individual tasks to Piscina worker threads for each route, introducing per-task IPC serialization and event loop scheduling overhead on large applications with thousands of routes.

What is the new behavior?

  1. Server application output files and manifests are stored as Uint8Array views backed by SharedArrayBuffer via createSharedServerFiles, allowing zero-copy memory sharing across all worker threads and ESM loader hooks.
  2. Routes requiring rendering are dynamically batched (up to 50 routes per worker job) before dispatching to worker threads, reducing IPC round-trips.
  3. Updated render-worker.ts to support batch rendering requests while maintaining backward compatibility and per-route error trapping.
  4. Static redirects are generated synchronously on the main thread.

Does this PR introduce a breaking change?

  • Yes
  • No

@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Aug 24, 2026
@alan-agius4
alan-agius4 force-pushed the perf-prerender-route-batching-shared-bundles branch 2 times, most recently from 7986ca2 to 04e0890 Compare August 24, 2026 10:53
@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Aug 24, 2026
@alan-agius4
alan-agius4 requested a review from clydin August 24, 2026 10:53
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 24, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review August 24, 2026 10:53

@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 server-side prerendering by transitioning in-memory files to zero-copy Uint8Array buffers backed by SharedArrayBuffer and batching route rendering requests to reduce IPC overhead across worker threads. It also adds comprehensive unit tests for these changes. The feedback suggests adding an inline comment to explain the batching heuristic formula for better maintainability.

Comment thread packages/angular/build/src/utils/server-rendering/prerender.ts
@alan-agius4
alan-agius4 force-pushed the perf-prerender-route-batching-shared-bundles branch from 04e0890 to 25db34e Compare August 24, 2026 10:58
…er bundles

Back in-memory server bundles with SharedArrayBuffer to eliminate V8 structuredClone
memory duplication across worker threads and loader hooks.

Batch routes dynamically during prerendering to amortize IPC messaging and event
loop scheduling overhead.
@alan-agius4
alan-agius4 force-pushed the perf-prerender-route-batching-shared-bundles branch from 25db34e to 6c170b2 Compare August 24, 2026 11:05
@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 24, 2026
@alan-agius4
alan-agius4 merged commit 62999ca into angular:main Aug 25, 2026
40 checks passed
@alan-agius4
alan-agius4 deleted the perf-prerender-route-batching-shared-bundles branch August 25, 2026 06:07
@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 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