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
experiment with reducing import time #7423
Conversation
Worth noting that the big win from not importing |
FYI the current reduction is huge on Windows compared to before for me: Before:
After:
|
I don't know how much it would help here but in case you're unaware since Python 3.7 there exists a way to dynamically set module attributes: https://peps.python.org/pep-0562/ For example, in Hatch I have core functionality that lets people migrate their build configuration and project metadata automatically and I use that to patch setuptools: https://github.com/pypa/hatch/blob/hatch-v1.7.0/src/hatch/cli/new/migrate.py#L317-L330 |
Anything I can do to help or test? |
Actually, I found out that there is a well defined way to do lazy imports based on the PEP I mentioned that has already become a standard within the scientific Python community: I'm going to begin introducing that at work in fact soon based on successful preliminary tests I did today |
I think we should do the first two things on my list, anything else if going to take longer. Probably easiest via a new pr. Of course anyone else is welcome to have a dig and see if they can improve import time. |
I've made some progress on this in #7590, this should be released in v2.4 today. If that goes well and we don't receive any issues about problems with module |
Is there anything I can do to help or test? |
ref #7409
Experiment with reducing import time.
Removing dataclasses is pretty hard since:
annotated-types
, I think persuading @adriangb to remove dataclasses from there and using a proxy/hack like we do here is pretty unlike@dataclass_transform(field_specifiers=(dataclasses.field, Field))
, while this is only required by type checkers, I think it would be quite to remove them and keepdataclass_transform
behaviour the same, maybe it's possibleFrom my experience here the low hanging fruit to improve performance times are:
deprecated
, using a mixture of local imports andpydantic.__init__.__getattr__
pydantic.types
, and add it all it's exports topydantic.__init__.__getattr__
pydantic_core.core_schema
deferred_dataclasses
provides some improvements even through it doesn't yet avoid dataclasses being imported