Skip to content

bpo-42862: Use functools.lru_cache iso. _sqlite.Cache in sqlite3 module - #24203

Merged
pablogsal merged 18 commits into
python:mainfrom
erlend-aasland:sqlite-cache
Jun 3, 2021
Merged

bpo-42862: Use functools.lru_cache iso. _sqlite.Cache in sqlite3 module#24203
pablogsal merged 18 commits into
python:mainfrom
erlend-aasland:sqlite-cache

Conversation

@erlend-aasland

@erlend-aaslanderlend-aasland commented Jan 12, 2021

Copy link
Copy Markdown
Contributor

@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

@rhettinger Would you mind reviewing the use of functools.lru_cache in this PR?

@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

FYI @berkerpeksag, I've rebased onto master again, bco. #24801.

@erlend-aasland

erlend-aasland commented May 2, 2021

Copy link
Copy Markdown
ContributorAuthor

Rebased onto master to resolve conflicts. Also added a tiny optimisation: increase the default cache size from 100 to 128. I'm guessing it is way to late to get this into 3.10 now :)

@erlend-aasland
erlend-aaslandforce-pushed the sqlite-cache branch 2 times, most recently from 6ceadcd to c561babCompareMay 2, 2021 20:49
@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

@pablogsal, two questions:

  1. There's some issues with the Windows tests. I've added a workaround in f1f023b, but I don't understand why this is needed. One possible reason could be that SQLite is holding on to TESTFN after the test is finished. I haven't devoted too much time to investigate this yet.
  2. Is it ok to request Raymonds review here? functools is his domain.

Comment threadDoc/library/sqlite3.rst Outdated
@pablogsal

Copy link
Copy Markdown
Member

2. Is it ok to request Raymonds review here? functools is his domain.

Unless you are changing the module itself, is not very relevant, but you are always free to ask for his advice :)

  • There's some issues with the Windows tests. I've added a workaround in f1f023b, but I don't understand why this is needed. One possible reason could be that SQLite is holding on to TESTFN after the test is finished. I haven't devoted too much time to investigate this yet.

That seems like some genuine problem. Maybe @vstinner has seen this before?

Comment threadModules/_sqlite/connection.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Be careful with static globals as this is not subinterpreter-friendly. @vstinner or @ericsnowcurrently can explain further.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Currently, there's no module state in sqlite3. Converting the sqlite3 state to heap types has been the first step on the path to sqlite3 multi-phase initialisation and module state. I can use this PR to establish a static global state, and put _lru_cache there.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I added a global state struct and put _lru_cache there. I can add the rest of the static data to it in a separate PR. One step closer to multi-phase init and sub-interpreter support.

See bb186dca837c805cf5d78ae7675d8a43a0b217cd

Comment threadModules/_sqlite/connection.c Outdated
Comment threadModules/_sqlite/connection.c Outdated
Comment threadLib/sqlite3/test/hooks.py Outdated
@pablogsal

Copy link
Copy Markdown
Member

When you are done with the fixes, could you test with the buildbots using the buildbot label?

@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

I messed up the previous merge so I had to rebase and force push. Sorry 'bout the mess.

@erlend-aasland
erlend-aasland marked this pull request as ready for review May 25, 2021 22:18
Comment threadLib/sqlite3/test/dbapi.py Outdated
@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@pablogsal

Copy link
Copy Markdown
Member

@erlend-aasland is this still a draft (I assume not)? :)

@erlend-aasland
erlend-aasland marked this pull request as ready for review June 3, 2021 19:55
@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

is this still a draft (I assume not)? :)

Nope, I was waiting for the CI, just to be sure :)

@pablogsal
pablogsal merged commit f461a7f into python:mainJun 3, 2021
@erlend-aasland
erlend-aasland deleted the sqlite-cache branch June 3, 2021 19:59
@pablogsal

Copy link
Copy Markdown
Member

Great job @erlend-aasland! 🎉

@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

Thanks, Pablo! 😃

Sign up for freeto 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.

5 participants

@erlend-aasland@pablogsal@bedevere-bot@berkerpeksag@the-knights-who-say-ni