Commit 970c127
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 42.3%.
- 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,182.0 ms | 1,180.5 ms | 1.00x faster (-0.1%) |
| Cold Build Duration (min / max) | 1,151.7 ms / 1,228.2 ms | 1,156.8 ms / 1,224.2 ms | +5.1 ms / -4.0 ms |
| P95 Build Latency | 1,228.2 ms | 1,224.2 ms | -0.3% (-4.0 ms) |
| Throughput | 2,962.4 ops/sec | 2,966.1 ops/sec | +0.1% (+3.7 ops/sec) |
| I18n Inlining Duration (Pure mean) | 696.0 ms | 217.9 ms | 3.19x faster (-68.7%) |
| I18n Inlining (min / max) | 678.7 ms / 730.5 ms | 196.4 ms / 243.2 ms | 3.46x / 3.00x 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,786.0 MB | +1,519.7 MB | -45.5% (-1,266.3 MB saved) |
| Final Process RSS | 2,842.1 MB | 1,576.4 MB | -44.5% (-1,265.7 MB saved) |
| Kernel System CPU | 2,355.1 ms | 1,358.3 ms | -42.3% (1.73x less kernel CPU) |
| Total CPU (User + Kernel) | 16,198.8 ms | 10,808.7 ms | -33.3% (1.50x 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,267.1 ms | 5,651.3 ms | +7.3% (+384.2 ms) |
| E2E Build Duration (min / max) | 5,187.5 ms / 5,351.7 ms | 5,595.6 ms / 5,737.8 ms | +408.1 ms / +386.1 ms |
| P95 Build Latency | 5,351.7 ms | 5,737.8 ms | +7.2% (+386.1 ms) |
| Process RSS Delta | +2,215.3 MB | +2,124.3 MB | -4.1% (-91.0 MB saved) |
| Final Process RSS | 2,296.2 MB | 2,204.7 MB | -4.0% (-91.5 MB saved) |
| Kernel System CPU | 3,087.4 ms | 3,000.0 ms | -2.8% (1.03x less kernel CPU) |
| Total CPU (User + Kernel) | 19,968.8 ms | 17,906.2 ms | -10.3% (-2,062.6 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 ~380 ms wall-clock time for -2.06s 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 204eafc commit 970c127
9 files changed
Lines changed: 603 additions & 151 deletions
File tree
- packages/angular/build/src
- tools
- esbuild
- sass
- utils
Lines changed: 158 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
42 | 54 | | |
43 | | - | |
| 55 | + | |
44 | 56 | | |
45 | 57 | | |
46 | 58 | | |
| |||
62 | 74 | | |
63 | 75 | | |
64 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
65 | 102 | | |
66 | 103 | | |
67 | 104 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
71 | 108 | | |
72 | 109 | | |
73 | 110 | | |
| |||
79 | 116 | | |
80 | 117 | | |
81 | 118 | | |
82 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
83 | 131 | | |
84 | 132 | | |
85 | 133 | | |
86 | 134 | | |
87 | | - | |
| 135 | + | |
88 | 136 | | |
89 | 137 | | |
90 | 138 | | |
91 | 139 | | |
92 | 140 | | |
93 | 141 | | |
94 | 142 | | |
| 143 | + | |
| 144 | + | |
95 | 145 | | |
96 | 146 | | |
97 | | - | |
98 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
99 | 154 | | |
100 | | - | |
101 | | - | |
102 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
103 | 171 | | |
104 | | - | |
105 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
106 | 178 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 179 | + | |
110 | 180 | | |
111 | 181 | | |
112 | 182 | | |
| |||
121 | 191 | | |
122 | 192 | | |
123 | 193 | | |
124 | | - | |
| 194 | + | |
125 | 195 | | |
126 | 196 | | |
127 | 197 | | |
128 | 198 | | |
129 | | - | |
| 199 | + | |
| 200 | + | |
130 | 201 | | |
131 | 202 | | |
132 | 203 | | |
133 | | - | |
134 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
135 | 220 | | |
136 | 221 | | |
137 | 222 | | |
| |||
144 | 229 | | |
145 | 230 | | |
146 | 231 | | |
147 | | - | |
148 | | - | |
| 232 | + | |
| 233 | + | |
149 | 234 | | |
150 | 235 | | |
151 | 236 | | |
152 | 237 | | |
153 | 238 | | |
154 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
155 | 242 | | |
156 | 243 | | |
157 | 244 | | |
| |||
161 | 248 | | |
162 | 249 | | |
163 | 250 | | |
| 251 | + | |
164 | 252 | | |
165 | 253 | | |
166 | 254 | | |
| |||
178 | 266 | | |
179 | 267 | | |
180 | 268 | | |
181 | | - | |
| 269 | + | |
182 | 270 | | |
183 | 271 | | |
184 | 272 | | |
| |||
187 | 275 | | |
188 | 276 | | |
189 | 277 | | |
| 278 | + | |
190 | 279 | | |
191 | 280 | | |
192 | 281 | | |
| |||
352 | 441 | | |
353 | 442 | | |
354 | 443 | | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
355 | 479 | | |
356 | 480 | | |
357 | 481 | | |
| |||
370 | 494 | | |
371 | 495 | | |
372 | 496 | | |
| 497 | + | |
373 | 498 | | |
374 | 499 | | |
375 | 500 | | |
| |||
391 | 516 | | |
392 | 517 | | |
393 | 518 | | |
394 | | - | |
| 519 | + | |
395 | 520 | | |
396 | 521 | | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
420 | 528 | | |
421 | 529 | | |
422 | 530 | | |
| |||
0 commit comments