Closed criemen closed 6 months ago
On top of that, RAM usage after loading githubkit is significantly higher with pydantic v2 as well.
For our gunicorn server (4 process), with 0.10.7 we see a baseline of <800MB, whereas with githubkit 0.11.0a0 we see 2.3GB.
Due to the huge number of models, i decide to use lazy import to improve the performance. #11
The models will be loaded when the api first time imported.
To lazy import the models, the codegen should be changed to group the models for each api version and each api client (api scope such as repo
, issues
)
I investigated this a bit more: Some things that help (but model building is still slow!) are:
update_forward_refs()
to model_rebuild()
in models.py
- the former is deprecated, and calls the latter with force=True, so the latter is doing less workmodel_rebuild
on all models anyways, you can experiment with setting "defer_build": True
for all models through the config settings in GithubRestModel
Hey @yanyongyu 👋 Since we benefit a lot from your work at polarsource/polar, I just pledged 100$ on this issue! Feel free to claim it over at https://polar.sh/ 😄
Hello, i'm currently working on lazy importing and api versioning. you can see it on the https://github.com/yanyongyu/githubkit/tree/feat/codegen-refactor branch. The first step which i'm working on is to refactor the codegen to support api versioning and top-level lazy loading (by defer import).
Hi @criemen @frankie567 , i have just published a release 0.11.0a2
with fully lazy loading feature. You can test it by installing the pre-release.
Hi,
when testing the pydantic v2 prelease (0.11.0a0), we're seeing a big performance decrease on process startup time. My test file:
went from ca. 1.6sec to 3.8sec on my M1 macbook. On production systems that have less powerful CPUs and slower I/Os, we're seeing this take 15-20sec now.
When interrupting the loading process with Ctrl+C, we see a stacktrace ala which hints at pydantic being the issue.
Is there anything that can be done about this?
Upvote & Fund