Skip to content
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

refactor: update Pydantic imports #625

Merged
merged 1 commit into from
Dec 28, 2024
Merged

Conversation

adhtruong
Copy link
Collaborator

Description

(polyfactory) ➜  polyfactory git:(perf-refactor-pydantic-imports) ✗ cat test.sh 
#!/usr/bin/env sh

.venv-fast/bin/python -m pip install -e . 
.venv-fast/bin/python -m pip install "pydantic<2.5.0"
.venv-slow/bin/python -m pip install -e . 
.venv-slow/bin/python -m pip install "pydantic==2.5.0"

.venv-slow/bin/python t.py
.venv-fast/bin/python t.py

with before and after this change

0.22203758300747722
0.1394521670008544
---
0.1482207500084769
0.13731049999478273
  • Explanation here is pydantic now performs dynamic imports in some cases so affects performance when using attrs from the module. By importing directly for common attributes we avoid this cost.

Closes

@adhtruong adhtruong requested a review from guacs as a code owner December 28, 2024 09:54
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/625

@adhtruong adhtruong enabled auto-merge (squash) December 28, 2024 10:07
Copy link
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adhtruong adhtruong merged commit a7dda85 into main Dec 28, 2024
24 checks passed
@adhtruong adhtruong deleted the perf-refactor-pydantic-imports branch December 28, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants