-
Notifications
You must be signed in to change notification settings - Fork 292
Move field_name
from runtime to schema generation time
#715
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
Conversation
CodSpeed Performance ReportMerging #715 will improve performances by 13.51%Comparing Summary
Benchmarks breakdown
|
Just an idea I got from discussion in #714 . We could move the whole |
field_name
from runtime to schema generation time
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #715 +/- ##
==========================================
- Coverage 93.63% 93.63% -0.01%
==========================================
Files 99 99
Lines 13913 13895 -18
Branches 25 25
==========================================
- Hits 13028 13010 -18
Misses 879 879
Partials 6 6
Continue to review full report in Codecov by Sentry.
|
please review |
I measured #726 locally and am getting 22.09±0.5us on this branch vs. 26.17±0.362 on main. |
Benchmarks are now reflecting a 13.5% speedup :) |
@samuelcolvin Adrian and I discussed, and I think Adrian was going to try to implement the pydantic side before merging this to make sure there were no surprises, but we also want to make sure you don't have objections before merging. (As far as I'm concerned this is good, at least assuming it can be made to work with pydantic, but figure there's a chance I'm not considering something important.) |
I created pydantic/pydantic#6392, it looks pretty good I think. If that looks good to you David lets merge this and I can update that PR once we have a new core release |
Pydantic should have this information when it is building the schema so this removes a bit of branching that happens at runtime, including a runtime error if the schema is misconfigured and a field from the poor catch-all
Extra
struct.If we take this one step further we could replace
field_name
withfield_info
which could be an arbitrary generic type, giving us more flexibility on the Pydantic side to e.g. make it aFieldInfo
instead of a string which you then need to look up in the model class. This change in particular would allow us to passFieldInfo
intoAnnotated
validators if we wanted to.Selected Reviewer: @dmontagu