Commit b8aebf4
perf(types): defer pydantic core-schema builds to cut import memory
Add defer_build=True to AdCPBaseModel so each generated model's
pydantic-core validator/serializer is built lazily on first use rather
than at class definition. With ~1500 generated model classes, eager
builds dominate `import adcp` memory; deferring builds only the working
set (18 of 1564 classes build at import).
Because model_dump forces serialize_as_any=True, pydantic-core dispatches
serialization to each nested instance's own class serializer, which under
defer_build stays a placeholder and bypasses the lazy-build trigger. Walk
the instance graph on that error and rebuild the still-deferred classes,
then retry, so only models that appear in real payloads get built.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7c81056 commit b8aebf4
2 files changed
Lines changed: 76 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
41 | 71 | | |
42 | 72 | | |
43 | 73 | | |
| |||
229 | 259 | | |
230 | 260 | | |
231 | 261 | | |
232 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
233 | 268 | | |
234 | 269 | | |
235 | 270 | | |
| |||
243 | 278 | | |
244 | 279 | | |
245 | 280 | | |
246 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
247 | 288 | | |
248 | 289 | | |
249 | 290 | | |
250 | 291 | | |
251 | 292 | | |
252 | 293 | | |
253 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
254 | 301 | | |
255 | 302 | | |
256 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 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 | + | |
130 | 156 | | |
131 | 157 | | |
132 | 158 | | |
| |||
0 commit comments