Improve schema gen for nested dataclasses#9114
Conversation
CodSpeed Performance ReportMerging #9114 will improve performances by 53.81%Comparing Summary
Benchmarks breakdown
|
|
Please review |
|
This is very nice! Do we have any benchmarks? That'd be a nice to have so we can track this. Assuming you wrote some to come up with this change, can we commit them along with other benchmarks (if they don't already exist)? There's several scenarios where I imagine we do need to rebuild: # unsubstituted typevars
class Inner(BaseModel, Generic[T]):
x: T
class Outer(BaseModel):
inner: Inner[int] # need to rebuild innner
# cyclical forward references
class InnerFwd(BaseModel):
outer: OuterFwd
class OuterFwd(BaseModel):
inner: InnerFwdAnd probably others I'm not thinking of. Do we have tests showing that these use cases work correctly? |
Deploying pydantic-docs with
|
| Latest commit: |
ee3ebfb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bdfaf89c.pydantic-docs2.pages.dev |
| Branch Preview URL: | https://make-schema-gen-better.pydantic-docs2.pages.dev |
Good point - I've added tests for both of these cases both to
I've added a benchmark for the basic case with a nested model and dataclass. I think this should work, though I might have to add this in a separate PR so that we get a comparison in |
|
Ah, added this to a separate PR: #9121 |
This reverts commit c95fe75.
When we have the schema available for a
dataclass(or other type with__pydantic_core_schema) don't rebuild! Greatly improves schema generation time + greatly minimizes the number of recursive schema building calls.Selected Reviewer: @hramezani