-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Remove apparently-unnecessary model_rebuild #5371
Conversation
I'll note here that this doesn't have as dramatic of an effect on overall pytest runtime as it does on hot-loop generic model creation. I ran
I also checked and there doesn't seem to be any meaningful changes to fixtures in I also checked, adding |
Some profiling for the record from typing import Generic, List, Type, TypeVar
from pydantic import BaseModel
T = TypeVar('T')
C = TypeVar('C')
class A(BaseModel, Generic[T, C]):
x: T
y: C
class B(A[int, C], BaseModel, Generic[C]):
pass
models: List[Type[BaseModel]] = []
for i in range(1_000):
models.append(type(f'M{i}', (BaseModel,), {}))
for m in models:
B[m] A pyinstrument report: JSON data for https://www.speedscope.app/: |
It turns out the garbage collection fixture was the one that had increased in runtime from ~10ms to ~30ms. Perhaps worth looking into more, but removing from most tests, the runtime becomes much more similar pre- and post-refactor. |
@samuelcolvin I think unless this change seems suspicious to you we should merge this, and if the garbage collection stuff concerns you at all let's just create a separate issue for that. Given the massive simplifications I realized were possible in #5361 I just think that the improvements to model creation eliminated the need for some of the hacks that I had to use to get it working in the first place. |
Amazing, thank you. |
Partially addresses the performance issues noted in #5351