Commit 24c1f32
Optimize code generation with parallel file writing
tl;dr: make codegen much faster through parallel writing of files
We have a _very large_ API design, with over 100 services, which
generates almost 3k files with `goa generate`. As our API has grown,
running `goa generate` has got really slow.
This commit adds timing data to the `--debug` output.
Then, the lowest-hanging-fruit optimisation has been applied: writing
all the output files in parallel.
---
As a recap, the generation process has several stages:
1. **Compile temporary binary**: Goa creates a temporary Go program that
imports the design package (which triggers package initialization and
DSL execution via blank import)
2. **Execute binary**: The binary runs through multiple phases:
- Package initialization (runs DSL definitions)
- `eval.RunDSL()` - processes the DSL in 4 phases (execute, prepare,
validate, finalize)
- `generator.Generate()` - produces the actual Go files
Measuring codegen for the incident-io codebase on 3,036 generated files:
**Total time: 61 seconds**
Breakdown:
- build.Import: 117ms
- NewGenerator (packages.Load): 52ms
- Write (generate main.go): 14ms
- Compile (go get + go build): 3.6s
- packages.Load: 47ms
- go get: 514ms
- go build: 3.0s
- **Run (execute binary): 52.2s** 1 parent aabae26 commit 24c1f32
File tree
6 files changed
+239
-35
lines changed- cmd/goa
- codegen/generator
- expr
6 files changed
+239
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | | - | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
58 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
| |||
132 | 137 | | |
133 | 138 | | |
134 | 139 | | |
| 140 | + | |
135 | 141 | | |
136 | 142 | | |
137 | 143 | | |
| |||
154 | 160 | | |
155 | 161 | | |
156 | 162 | | |
157 | | - | |
| 163 | + | |
158 | 164 | | |
159 | 165 | | |
| 166 | + | |
160 | 167 | | |
161 | 168 | | |
162 | 169 | | |
163 | 170 | | |
164 | 171 | | |
165 | 172 | | |
166 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
167 | 178 | | |
| 179 | + | |
168 | 180 | | |
169 | 181 | | |
170 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
171 | 186 | | |
172 | 187 | | |
| 188 | + | |
173 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
174 | 193 | | |
175 | 194 | | |
176 | 195 | | |
| |||
183 | 202 | | |
184 | 203 | | |
185 | 204 | | |
186 | | - | |
| 205 | + | |
187 | 206 | | |
188 | 207 | | |
189 | 208 | | |
| |||
210 | 229 | | |
211 | 230 | | |
212 | 231 | | |
213 | | - | |
| 232 | + | |
214 | 233 | | |
215 | 234 | | |
216 | 235 | | |
| |||
291 | 310 | | |
292 | 311 | | |
293 | 312 | | |
| 313 | + | |
294 | 314 | | |
295 | 315 | | |
296 | 316 | | |
| |||
311 | 331 | | |
312 | 332 | | |
313 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
314 | 339 | | |
315 | 340 | | |
316 | 341 | | |
| 342 | + | |
| 343 | + | |
317 | 344 | | |
318 | 345 | | |
319 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
320 | 352 | | |
321 | 353 | | |
322 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
323 | 359 | | |
324 | 360 | | |
325 | 361 | | |
| |||
328 | 364 | | |
329 | 365 | | |
330 | 366 | | |
331 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
332 | 370 | | |
333 | 371 | | |
334 | 372 | | |
335 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
336 | 377 | | |
337 | 378 | | |
338 | 379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
85 | 93 | | |
86 | 94 | | |
87 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
88 | 99 | | |
89 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
90 | 105 | | |
| 106 | + | |
91 | 107 | | |
92 | 108 | | |
93 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
94 | 113 | | |
95 | | - | |
| 114 | + | |
| 115 | + | |
96 | 116 | | |
97 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
98 | 121 | | |
99 | | - | |
| 122 | + | |
| 123 | + | |
100 | 124 | | |
101 | 125 | | |
102 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
103 | 130 | | |
104 | 131 | | |
105 | 132 | | |
| |||
0 commit comments