Commit 712971c
perf(@angular/build): share i18n translations with the inliner workers by reference
`inlineForLocale` passes the locale's translations to `workerPool.run()` once per file, so every
request structure-clones the whole set of messages into a Worker. For an application with a few
thousand localized chunks and a catalog of tens of thousands of messages, that is tens of
gigabytes of short-lived allocation and minutes of serialization on the builder's main thread.
Because each clone is several megabytes it lands in V8's large object space, where only a major
collection reclaims it, so a build with a heap ceiling sized for the machine can exhaust the
machine before the collector intervenes.
The messages are now serialized once per locale and passed as a Blob. Cloning a Blob shares its
data by reference, which is the same reason the application files are already passed that way.
Each Worker deserializes the messages once per locale and retains only the active locale, so at
most one set of messages is held per Worker.
`node:v8` serialization is used rather than JSON so that the messages arrive in the Worker
exactly as the structured clone delivered them today. `translate` only reads from the messages,
so sharing one deserialized set across the files of a locale is safe.
Measured on an application with 1,721 localized chunks across 9 locales, where the largest
catalog serializes to 6.0MB: inlining 400 chunks across 4 locales went from 23,679ms and 14,504MB
peak RSS to 915ms and 1,118MB, with byte-identical output.
(cherry picked from commit 596847f)1 parent 3d7e363 commit 712971c
2 files changed
Lines changed: 90 additions & 11 deletions
Lines changed: 60 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | | - | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
56 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
57 | 62 | | |
58 | | - | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
62 | | - | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 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 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
69 | 108 | | |
70 | 109 | | |
71 | 110 | | |
| |||
80 | 119 | | |
81 | 120 | | |
82 | 121 | | |
83 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
84 | 128 | | |
85 | 129 | | |
86 | 130 | | |
| |||
98 | 142 | | |
99 | 143 | | |
100 | 144 | | |
101 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
102 | 151 | | |
103 | 152 | | |
104 | 153 | | |
| |||
136 | 185 | | |
137 | 186 | | |
138 | 187 | | |
| 188 | + | |
139 | 189 | | |
140 | 190 | | |
141 | 191 | | |
142 | 192 | | |
143 | 193 | | |
144 | 194 | | |
| 195 | + | |
145 | 196 | | |
146 | 197 | | |
147 | 198 | | |
| |||
169 | 220 | | |
170 | 221 | | |
171 | 222 | | |
172 | | - | |
| 223 | + | |
173 | 224 | | |
174 | 225 | | |
175 | | - | |
| 226 | + | |
176 | 227 | | |
177 | 228 | | |
178 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
22 | 37 | | |
23 | 38 | | |
24 | 39 | | |
| |||
125 | 140 | | |
126 | 141 | | |
127 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
128 | 147 | | |
129 | 148 | | |
130 | 149 | | |
| |||
160 | 179 | | |
161 | 180 | | |
162 | 181 | | |
163 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
164 | 187 | | |
165 | 188 | | |
166 | 189 | | |
| |||
227 | 250 | | |
228 | 251 | | |
229 | 252 | | |
230 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
231 | 259 | | |
232 | 260 | | |
233 | 261 | | |
| |||
0 commit comments