Commit d533bfa
committed
perf(@angular/build): consolidate build worker pools with shared router
Unify isolated per-subsystem worker pools (JavaScriptTransformer, SassService, I18nInliner) into a single singleton WorkerPool routed via dynamic task dispatching (shared-worker-router.ts).
- Reduce active worker threads by 66.7% (24 -> 8 threads), eliminating thread thrashing and reducing kernel system CPU time by 40.7%.
- Implement zero-copy transferable file and translation Blobs, avoiding IPC serialization overhead.
- Add bounded Map caching (fileDataCache, deserializedTranslations) with fileKey and translationKey in the i18n inliner worker isolate, achieving 100% AST and 99.8% translation cache hit rates across locales without memory leaks.
- Standardize discriminated union tasks (InlineI18nFileTask, InlineI18nCodeTask) with zero-allocation synchronous dispatching.
### Benchmark 1: Subsystem Benchmark (500 Components, 500 SCSS Stylesheets, 5 Locales / 3,500 operations, 5 iterations)
| Metric | Baseline (`main`) | Consolidated (`perf-build-singleton-shared-worker-pool`) | Delta / Speedup |
| :--- | :--- | :--- | :--- |
| Active Worker Threads | 24 threads | 8 threads | -66.7% threads (-16 threads) |
| Cold Build Duration (mean) | 1,192.6 ms | 1,214.9 ms | +1.9% (+22.3 ms) |
| Cold Build Duration (min / max) | 1,180.4 ms / 1,206.1 ms | 1,189.2 ms / 1,236.0 ms | +8.8 ms / +29.9 ms |
| P95 Build Latency | 1,206.1 ms | 1,236.0 ms | +2.5% (+29.9 ms) |
| Throughput | 2,935.1 ops/sec | 2,881.5 ops/sec | -1.8% (-53.6 ops/sec) |
| I18n Inlining Duration (Pure mean) | 703.1 ms | 238.5 ms | 2.95x faster (-66.1%) |
| I18n Inlining (min / max) | 697.3 ms / 711.0 ms | 216.2 ms / 258.3 ms | 3.23x / 2.75x faster |
| AST Cache Hit Rate (Subsequent Locales) | 0.0% (0 / 2,000) | 100.0% (2,000 / 2,000) | 100.0% cache hit rate |
| Translation Cache Hit Rate | 0.0% (0 / 2,500) | 99.8% (2,495 / 2,500) | 99.8% cache hit rate |
| Process RSS Delta | +2,779.1 MB | +1,517.4 MB | -45.4% (-1,261.7 MB saved) |
| Final Process RSS | 2,835.6 MB | 1,573.9 MB | -44.5% (-1,261.7 MB saved) |
| Kernel System CPU | 2,355.1 ms | 1,396.7 ms | -40.7% (1.69x less kernel CPU) |
| Total CPU (User + Kernel) | 16,252.7 ms | 11,106.8 ms | -31.7% (1.46x CPU efficiency) |
### Benchmark 2: End-to-End `ng build` Application Benchmark (500 Components, 500 SCSS Stylesheets, 5 Locales, 5 iterations)
| Metric | Baseline (`main`) | Consolidated (`perf-build-singleton-shared-worker-pool`) | Delta / Speedup |
| :--- | :--- | :--- | :--- |
| Active Worker Threads | 24 threads | 8 threads | -66.7% threads (-16 threads) |
| E2E Build Duration (mean) | 5,376.4 ms | 5,728.0 ms | +6.5% (+351.6 ms) |
| E2E Build Duration (min / max) | 5,292.6 ms / 5,463.4 ms | 5,610.4 ms / 5,782.3 ms | +317.8 ms / +318.9 ms |
| P95 Build Latency | 5,463.4 ms | 5,782.3 ms | +5.8% (+318.9 ms) |
| Process RSS Delta | +2,016.9 MB | +1,806.2 MB | -10.4% (-210.7 MB saved) |
| Final Process RSS | 2,098.1 MB | 1,887.0 MB | -10.1% (-211.1 MB saved) |
| Kernel System CPU | 2,156.0 ms | 1,915.7 ms | -11.1% (1.13x less kernel CPU) |
| Total CPU (User + Kernel) | 18,743.3 ms | 16,487.5 ms | -12.0% (-2,255.8 ms CPU saved) |
> **Note on Concurrency Bounds**: On high-core machines, baseline's 24 unthrottled concurrent threads across 3 independent pools allow concurrent execution of different compiler phases, whereas the consolidated 8-thread singleton enforces strict concurrency bounds, trading ~350 ms wall-clock time for -2.26s lower total CPU work and lower peak memory. This is particularly important for lower-end machines and resource-constrained CI/container environments to avoid severe CPU starvation, thread thrashing, and out-of-memory crashes.1 parent a877aa7 commit d533bfa
9 files changed
Lines changed: 689 additions & 163 deletions
File tree
- packages/angular/build/src
- tools
- esbuild
- sass
- utils
Lines changed: 200 additions & 66 deletions
Large diffs are not rendered by default.
Lines changed: 90 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
130 | 158 | | |
131 | 159 | | |
132 | 160 | | |
133 | 161 | | |
134 | 162 | | |
135 | 163 | | |
136 | 164 | | |
| 165 | + | |
137 | 166 | | |
138 | 167 | | |
139 | 168 | | |
| |||
148 | 177 | | |
149 | 178 | | |
150 | 179 | | |
| 180 | + | |
151 | 181 | | |
152 | 182 | | |
153 | 183 | | |
154 | 184 | | |
155 | | - | |
| 185 | + | |
156 | 186 | | |
157 | 187 | | |
158 | | - | |
| 188 | + | |
159 | 189 | | |
160 | 190 | | |
161 | 191 | | |
162 | 192 | | |
163 | 193 | | |
164 | 194 | | |
165 | | - | |
| 195 | + | |
166 | 196 | | |
167 | 197 | | |
168 | 198 | | |
169 | 199 | | |
170 | 200 | | |
171 | | - | |
172 | 201 | | |
173 | 202 | | |
174 | 203 | | |
| |||
199 | 228 | | |
200 | 229 | | |
201 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
202 | 234 | | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 235 | + | |
220 | 236 | | |
221 | 237 | | |
222 | 238 | | |
| |||
258 | 274 | | |
259 | 275 | | |
260 | 276 | | |
| 277 | + | |
261 | 278 | | |
262 | 279 | | |
263 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
264 | 286 | | |
265 | 287 | | |
266 | 288 | | |
| |||
339 | 361 | | |
340 | 362 | | |
341 | 363 | | |
| 364 | + | |
342 | 365 | | |
343 | 366 | | |
344 | 367 | | |
| |||
379 | 402 | | |
380 | 403 | | |
381 | 404 | | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
389 | 410 | | |
390 | 411 | | |
391 | 412 | | |
| |||
419 | 440 | | |
420 | 441 | | |
421 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
422 | 447 | | |
| 448 | + | |
423 | 449 | | |
424 | 450 | | |
425 | 451 | | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
438 | 469 | | |
439 | 470 | | |
440 | 471 | | |
| |||
493 | 524 | | |
494 | 525 | | |
495 | 526 | | |
496 | | - | |
| 527 | + | |
497 | 528 | | |
498 | 529 | | |
499 | 530 | | |
| |||
504 | 535 | | |
505 | 536 | | |
506 | 537 | | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
516 | 549 | | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
| 550 | + | |
526 | 551 | | |
527 | 552 | | |
528 | 553 | | |
| |||
536 | 561 | | |
537 | 562 | | |
538 | 563 | | |
539 | | - | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
540 | 569 | | |
541 | 570 | | |
542 | 571 | | |
| |||
Lines changed: 33 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
36 | 44 | | |
37 | 45 | | |
38 | 46 | | |
| |||
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
95 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
96 | 112 | | |
97 | 113 | | |
98 | | - | |
| 114 | + | |
99 | 115 | | |
100 | 116 | | |
101 | 117 | | |
| |||
137 | 153 | | |
138 | 154 | | |
139 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
140 | 160 | | |
141 | 161 | | |
142 | 162 | | |
| |||
156 | 176 | | |
157 | 177 | | |
158 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
159 | 184 | | |
160 | | - | |
| 185 | + | |
161 | 186 | | |
162 | 187 | | |
163 | 188 | | |
| |||
191 | 216 | | |
192 | 217 | | |
193 | 218 | | |
194 | | - | |
| 219 | + | |
195 | 220 | | |
196 | 221 | | |
197 | 222 | | |
| |||
206 | 231 | | |
207 | 232 | | |
208 | 233 | | |
209 | | - | |
| 234 | + | |
210 | 235 | | |
211 | 236 | | |
212 | 237 | | |
213 | 238 | | |
214 | 239 | | |
215 | 240 | | |
216 | 241 | | |
217 | | - | |
218 | | - | |
| 242 | + | |
| 243 | + | |
219 | 244 | | |
220 | 245 | | |
221 | 246 | | |
| |||
0 commit comments