Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
gh-118761: Improve import time ofsqlite3
#131796
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@Wulian233 In your benchmark the Also |
Uh oh!
There was an error while loading.Please reload this page.
brianschubert commentedMar 27, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'm also a bit surprised that
Which, if I'm reading it right, says that importing |
Wulian233 commentedMar 27, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I think I got the name wrong at the time, it was a copy of the previous PR content, and here is the test I just run
|
Lib/sqlite3/dbapi2.py Outdated
@@ -20,9 +20,9 @@ | |||
# misrepresented as being the original software. | |||
# 3. This notice may not be removed or altered from any source distribution. | |||
import datetime | |||
import time |
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.
What's the point of the PR if the import is not removed? Lazy imports are therefore not used, then why should any speedup be expected, a slowdown is more likely?
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.
Already pointed out in#131796 (comment) :)
(But the PR author self-reviewed the review comment by declaring the review comment to be resolved, which is a controversial feature for github to even allow.)
picnixz commentedMar 29, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
To be precise, it's not importing Also, the benchmarks are quite unstable. The standard deviation is much higher than the mean itself! In practice, I think we don't gain anything else than stability (the stdev becomes smaller with the new implementation but again this could be noise). Can you check if And to be precise, we're not gaining a 2x speed-up. On average, we're only gaining a 1.1x speed-up and the standard deviation of this speed-up is And yes, I'm also surprised that we're gaining "that much" when we just make |
@Wulian233, can you address@picnixz'slast remark? |
Wulian233 commentedJun 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've reworked another version and it's going to be faster now I ran the command
Raw output: import time: self [us] | cumulative | imported packageimport time: 296 | 296 | winregimport time: 248 | 248 | _ioimport time: 70 | 70 | marshalimport time: 312 | 312 | ntimport time: 1637 | 2266 | _frozen_importlib_externalimport time: 1103 | 1103 | timeimport time: 1089 | 2191 | zipimportimport time: 75 | 75 | _codecsimport time: 793 | 868 | codecsimport time: 1926 | 1926 | encodings.aliasesimport time: 797 | 797 | encodings._win_cp_codecsimport time: 3400 | 6989 | encodingsimport time: 960 | 960 | encodings.utf_8import time: 75 | 75 | _codecs_cnimport time: 126 | 126 | _multibytecodecimport time: 1389 | 1590 | encodings.gbkimport time: 86 | 86 | _signalimport time: 59 | 59 | _abcimport time: 323 | 382 | abcimport time: 104 | 104 | _statimport time: 527 | 630 | statimport time: 1745 | 1745 | _collections_abcimport time: 126 | 126 | genericpathimport time: 229 | 229 | _winapiimport time: 3109 | 3463 | ntpathimport time: 2543 | 8760 | osimport time: 584 | 584 | _sitebuiltinsimport time: 1004 | 1004 | sitecustomizeimport time: 563 | 563 | usercustomizeimport time: 2043 | 12953 | siteimport time: 1104 | 1104 | linecacheimport time: 787 | 787 | _datetimeimport time: 1003 | 1790 | datetimeimport time: 704 | 704 | itertoolsimport time: 1147 | 1147 | keywordimport time: 128 | 128 | _operatorimport time: 1412 | 1540 | operatorimport time: 2293 | 2293 | reprlibimport time: 164 | 164 | _collectionsimport time: 4104 | 9950 | collectionsimport time: 2917 | 12866 | collections.abcimport time: 64 | 64 | _typesimport time: 1134 | 1197 | typesimport time: 136 | 136 | _functoolsimport time: 2652 | 3984 | functoolsimport time: 2658 | 6641 | _sqlite3import time: 74 | 74 | _contextvarsimport time: 1406 | 1479 | _py_warningsimport time: 2508 | 3987 | warningsimport time: 6431 | 31714 | sqlite3.dbapi2import time: 8592 | 40306 | sqlite3 D:\Python314>python -X importtime -c "import sqlite3_new" hyperfine test:
|
def main(*args): | ||
from argparse import ArgumentParser | ||
from textwrap import dedent | ||
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.
I do not see a valid reason to do code churn and delay imports for the sake of speeding upimport sqlite3.__main__
while assuming thatsqlite3.__main__.main()
is never called.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Improve import time of
sqlite3
by 1.5x fasterBenchmark on Windows10, CPython 3.14.0b1
I just realized today that I accidentally deleted an unmerged branch last month, which resulted in closing#129118 . My apologies for the oversight. I've now recreated the pull request - the content remains exactly the same as before
_sqlite3
sqlite3.dbapi2
sqlite3
(main)_sqlite3
is not much different.sqlite3.dbapi2
decreased significantly from 6431 to 5607sqlite3
module dropped very noticeably from 8592 to 4213