-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
Optimize field conversion to database format #1840
Merged
henadzit
merged 7 commits into
tortoise:develop
from
henadzit:chore/to_db_value_unused-code
Jan 10, 2025
Merged
Optimize field conversion to database format #1840
henadzit
merged 7 commits into
tortoise:develop
from
henadzit:chore/to_db_value_unused-code
Jan 10, 2025
+52
−132
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CodSpeed Performance ReportMerging #1840 will improve performances by 52.82%Comparing Summary
Benchmarks breakdown
|
Pull Request Test Coverage Report for Build 12631809925Details
💛 - Coveralls |
henadzit
force-pushed
the
chore/to_db_value_unused-code
branch
2 times, most recently
from
January 5, 2025 21:26
201554f
to
002513f
Compare
henadzit
force-pushed
the
chore/to_db_value_unused-code
branch
from
January 5, 2025 21:38
002513f
to
bafb6f7
Compare
henadzit
force-pushed
the
chore/to_db_value_unused-code
branch
from
January 5, 2025 23:08
0535db7
to
80684cc
Compare
henadzit
changed the title
WIP Remove unnecessary code from to_db_value
Optimize field conversion to database format
Jan 6, 2025
@abondar any chance you can have a look at this? Thanks! |
abondar
approved these changes
Jan 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
TO_DB_OVERRIDE
that is no longer needed after parametrization changes. The only exception is SQLite for whichsqlite3.register_adapter
was added - this is the same approach used by Django.BaseExecutor.column_map
. It was only required because ofTO_DB_OVERRIDE
.timezone.get_use_tz
,timezone.get_timezone
andtimezone.get_default_timezone
. Since these are called for each field withauto_now
orauto_now_add
, it provides a significant speedup.Motivation and Context
This PR improves the performance of field value conversion to the DB format (see the detailed report in the comments):
test_bulk_create_many_fields
benchmarktest_bulk_create_few_fields
test_create_many_fields
The speedup is primarily achieved by the removal of
self.model._meta.db
from theField. to_db_value
code. Thedb
property gets the current connection fromContextVar
and it was a relatively slow operation to do it for each field for each object inbulk_create
.How Has This Been Tested?
make ci
Checklist: