Repository navigation
test(@angular/build): add library builder scaling benchmark suite #34290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dherges
wants to merge
1
commit into
angular:main
Choose a base branch
from
dherges:test-ng-build-library-builder-benchmarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+651
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # `@angular/build:library` scaling benchmark | ||
|
|
||
| This benchmark measures how `@angular/build:library`'s cold build time scales with the number | ||
| of secondary entry points in an Angular Package Format (APF) library, across two structurally | ||
| different layouts (flat siblings vs. a deeply nested tree) and three component style variants | ||
| (inline template, inline template + styles, external template/stylesheet files). | ||
|
|
||
| ## Why | ||
|
|
||
| A comparison against [ng-packagr](https://github.com/ng-packagr/ng-packagr) (a third-party APF | ||
| build tool) found that its build time **per entry point** grows super-linearly once a library | ||
| has more than roughly 300-500 secondary entry points -- doubling the library size past that | ||
| point costs noticeably more than double the build time. This suite exists to check whether | ||
| `@angular/build:library`, a from-scratch build pipeline unrelated to ng-packagr's implementation, | ||
| shows the same growth on equivalent fixtures. | ||
|
|
||
| **Finding:** it does not. Across the same sweep (flat layout: 10/50/300/1000/2000 entries; deep | ||
| layout: tree depths 2/5/8/11, i.e. 4/32/256/2048 entries), `@angular/build:library`'s per-entry | ||
| cost keeps falling as the library grows, with no climb at the largest sizes tested. It is also | ||
| 1.8-13x faster than ng-packagr at matching sizes, with the gap widening as size increases. See | ||
| the PR description this suite was added alongside for the full writeup and caveats. | ||
|
|
||
| ## Running it | ||
|
|
||
| ```sh | ||
| pnpm build # or: pnpm admin build --local -- the benchmark measures the compiled builder, | ||
| # not TypeScript source, so it must exist at dist/@angular/build and | ||
| # dist/@angular-devkit/architect first | ||
| pnpm admin benchmark library-builder | ||
| ``` | ||
|
|
||
| Options: | ||
|
|
||
| ``` | ||
| --layout=<flat|deep> Fixture layout (default: flat) | ||
| --style=<inline|inline-scss|external> Component style variant (default: inline) | ||
| --sizes=<n,n,...> Entry-point counts to sweep, layout=flat only (default: 10,50,300,1000,2000) | ||
| --depths=<n,n,...> Tree depths to sweep, layout=deep only (default: 2,5,8,11) | ||
| --iterations=<n> Measured iterations per size (default: 2) | ||
| --json Output raw measurements as JSON instead of a human-readable log | ||
| ``` | ||
|
|
||
| Example: sweep the external-style variant at a few sizes with 3 iterations each: | ||
|
|
||
| ```sh | ||
| pnpm admin benchmark library-builder --style=external --sizes=100,500,1000 --iterations=3 | ||
| ``` | ||
|
|
||
| ## How it works | ||
|
|
||
| - `fixtures.mts` generates a synthetic library at a given size/layout/style: a primary entry | ||
| point, N secondary entry points (each a minimal standalone Angular component), and the | ||
| `angular.json`/`tsconfig.lib.json`/`package.json` scaffolding `@angular/build:library` needs. | ||
| Secondary entry points are declared as a single flat `exports` map in the root `package.json` | ||
| (the builder's actual convention), not as separate per-entry config files. | ||
| - `index.mts` times `architect lib:build` (the standalone `@angular-devkit/architect` CLI, | ||
| invoked directly -- no `ng` CLI needed) once per iteration via `child_process.spawnSync`, | ||
| discards the generated project afterwards, and reports per-size median build time. | ||
| - Because `@angular/build` and `@angular-devkit/architect` are Bazel-built workspace packages | ||
| rather than ordinary npm dependencies, a plain `pnpm install` never links them (or their own | ||
| dependencies) into the repo's root `node_modules` -- nothing in `dist/` is resolvable via a | ||
| bare `require()`/`import` otherwise. On first run, `index.mts` symlinks `@angular/build` and | ||
| `@angular-devkit/architect` from `dist/` into the root `node_modules`, then walks their | ||
| declared `dependencies` and links any of those still missing from the pnpm store. This only | ||
| touches `node_modules` (already gitignored) and is idempotent -- safe to run repeatedly or | ||
| alongside other work in the same checkout. | ||
|
|
||
| ## Methodology notes | ||
|
|
||
| - Each reported number is the **median** of the measured iterations, not the mean -- process-spawn | ||
| wall-clock timings are noisy and right-skewed, and the median is more representative of steady | ||
| state than an outlier-sensitive mean. | ||
| - Results are specific to the machine they were collected on. Run on one otherwise-idle machine | ||
| for a self-consistent sweep; absolute numbers will differ across hardware, though the _shape_ | ||
| of the curve (does per-entry cost grow with size, or not) is the more portable finding. | ||
| - This benchmark only covers **cold, one-shot builds**. It does not exercise incremental rebuilds | ||
| or watch mode. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
sizes,depths, anditerationsoptions are not validated for thelibrary-buildersubsystem. Invalid inputs (such as non-integers, negative numbers, or strings that parse toNaN) can cause silent failures or unexpected behavior in the benchmark runner. We should validate these options to ensure they are positive integers before running the benchmarks.