8000 bpo-42862: Use functools.lru_cache iso. _sqlite.Cache in sqlite3 module by erlend-aasland · Pull Request #24203 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 18 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tiny optimisation: increase the cache size from 100 to 128
  • Loading branch information
Erlend E. Aasland committed May 25, 2021
commit 6c6a4228c9d05a7237ed5d799ef33c0459910c97
2 changes: 1 addition & 1 deletion Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Module functions and constants
The :mod:`sqlite3` module internally uses a statement cache to avoid SQL parsing
overhead. If you want to explicitly set the number of statements that are cached
for the connection, you can set the *cached_statements* parameter. The currently
implemented default is to cache 100 statements.
implemented default is to cache 128 statements.

If *uri* is true, *database* is interpreted as a URI. This allows you
to specify options. For example, to open a database in read-only mode
Expand Down
4 changes: 2 additions & 2 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1237,10 +1237,10 @@ Add audit events for :func:`~sqlite3.connect/handle`,
:meth:`~sqlite3.Connection.load_extension`.
(Contributed by Erlend E. Aasland in :issue:`43762`.)


:mod:`sqlite3` now utilizes :meth:`functools.lru_cache` to implement the
connection statement cache. The statement cache can be accessed via the new
method :meth:`sqlite3.Connection.statement_cache`.
method :meth:`sqlite3.Connection.statement_cache`. As a small optimisation, the
default statement cache size has been increased from 100 to 128.
(Contributed by Erlend E. Aasland in :issue:`42862`.)

sys
Expand Down
4 changes: 2 additions & 2 deletions Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ def test_statement_cache(self):
info = cache.cache_info()
self.assertEqual(info.hits, 1)
self.assertEqual(info.misses, 1)
self.assertEqual(info.maxsize, 100)
self.assertEqual(info.maxsize, 128)
self.assertEqual(info.currsize, 1)

def test_statement_cache_maxsize(self):
maxsize = 5
maxsize = 8
testsize = maxsize + 1
cx = sqlite.connect(':memory:', cached_statements=maxsize)
for i in range(testsize):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:mod:`sqlite3` now utilizes :meth:`functools.lru_cache` to implement the
connection statement cache. The statement cache can be accessed via the new
method :meth:`sqlite3.Connection.statement_cache`. Patch by Erlend E.
Aasland.
method :meth:`sqlite3.Connection.statement_cache`. As a small optimisation, the
default statement cache size has been increased from 100 to 128.
Patch by Erlend E. Aasland.
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
PyObject* isolation_level = NULL;
PyObject* factory = NULL;
int check_same_thread = 1;
int cached_statements = 100;
int cached_statements = 128;
int uri = 0;
double timeout = 5.0;
int rc;
Expand Down
0