Skip to content

perf: run the SQLite engine in AUTOCOMMIT by default - #1852

Merged
collerek merged 1 commit into
masterfrom
perf/engine-level-autocommit
Oct 16, 2026
Merged

collerek merged 1 commit into
masterfrom
perf/engine-level-autocommit

Conversation

@collerek

Copy link
Copy Markdown
Collaborator

On SQLite every standalone query switched its pooled connection into AUTOCOMMIT and back through an engine view, costing two hops to the aiosqlite driver thread per query. The SQLite engine now runs in AUTOCOMMIT like MySQL (#1811), and standalone queries use the engine directly when it already is.

  • Standalone get / create / save / delete / count are 25–45% faster on SQLite; transactional paths are unchanged.
  • SQLite transactions keep their explicit BEGIN, which opens a real transaction on an AUTOCOMMIT connection, so savepoints and rollbacks work without an isolation switch. MySQL still switches to the server default isolation, so the Upgrade from 0.21 to 0.23 degraded our app performance significantly #1629 savepoint error can't come back.
  • Postgres is unchanged (no measurable gain), and a user-supplied isolation_level is respected.
  • test_standalone_query_uses_autocommit now checks autocommit via _is_autocommit_isolation() and that rows written in a transaction stay invisible to other connections until commit.

Standalone queries on SQLite switched each pooled connection into AUTOCOMMIT
and back via an engine view, which costs two hops to the aiosqlite driver
thread per query. The SQLite engine now runs in AUTOCOMMIT like MySQL, and
standalone queries use the engine directly when it already is. SQLite
transactions keep their explicit BEGIN, which opens a real transaction on an
AUTOCOMMIT connection, so no isolation switch is needed there. Postgres is
unchanged.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Oct 16, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 26.25%

⚠️ 112 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 70 improved benchmarks
✅ 56 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ ⚠️ test_deleting_individually[40] 98.6 ms 60.5 ms +62.98%
⚡ ⚠️ test_deleting_individually[20] 50.3 ms 31.2 ms +61.02%
⚡ ⚠️ test_deleting_individually[10] 26.1 ms 16.6 ms +57.37%
⚡ ⚠️ test_adding_saved_children_to_reverse_relation[40] 237.4 ms 160.1 ms +48.28%
⚡ ⚠️ test_updating_models_individually[40] 115.7 ms 78 ms +48.2%
⚡ ⚠️ test_adding_saved_children_to_reverse_relation[20] 120.4 ms 81.9 ms +47.06%
⚡ ⚠️ test_updating_models_individually[20] 58.9 ms 40.2 ms +46.55%
⚡ ⚠️ test_update_or_create_when_create[40] 117.2 ms 80.6 ms +45.45%
⚡ ⚠️ test_saving_models_individually[40] 115.4 ms 79.4 ms +45.32%
⚡ ⚠️ test_creating_models_individually[40] 116.8 ms 80.4 ms +45.31%
⚡ ⚠️ test_updating_models_individually[10] 30.7 ms 21.2 ms +44.89%
⚡ ⚠️ test_get_or_create_when_create[40] 253.8 ms 176.3 ms +43.97%
⚡ ⚠️ test_saving_models_individually[20] 60.9 ms 42.6 ms +42.9%
⚡ ⚠️ test_adding_saved_children_to_reverse_relation[10] 64.3 ms 45 ms +42.89%
⚡ ⚠️ test_creating_models_individually[20] 61.4 ms 43 ms +42.71%
⚡ ⚠️ test_update_or_create_when_create[20] 61.6 ms 43.2 ms +42.61%
⚡ ⚠️ test_get_or_create_when_create[20] 130.5 ms 91.9 ms +42.02%
⚡ ⚠️ test_get_or_create_when_create[10] 70.2 ms 50.8 ms +37.97%
⚡ ⚠️ test_update_or_create_when_create[10] 33.8 ms 24.6 ms +37.47%
⚡ ⚠️ test_saving_models_individually[10] 34 ms 24.8 ms +36.81%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/engine-level-autocommit (2247028) with master (e22d2d7)

Open in CodSpeed

@collerek
collerek merged commit 67d8106 into master Oct 16, 2026
11 checks passed
@collerek
collerek deleted the perf/engine-level-autocommit branch October 16, 2026 15:34
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