New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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: InnerFwd And probably others I'm not thinking of. Do we have tests showing that these use cases work correctly? |
Deploying pydantic-docs with Cloudflare Pages
|
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