Skip to content

perf: cache per-model parts of select building and row parsing - #1814

Merged
collerek merged 3 commits into
masterfrom
perf/get-query-building
Oct 8, 2026
Merged

collerek merged 3 commits into
masterfrom
perf/get-query-building

Conversation

@collerek

@collerek collerek commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

The labelled column list, the row extraction plan and default ORDER BY text clauses only depend on the model, alias and selected fields, but were rebuilt for every query. They're now cached (bounded lru caches), and the row plan is shared between querysets instead of per queryset.

Small win: single-row reads (get, first, exists, get_or_none) are 2-6% faster, get on the wide model ~10%. The rest of a get() is SQLAlchemy statement/cache-key work and the DB round trip.

Based on #1813 (pre-commit hook fails on master without it), will rebase once that's merged.

Since ruff 0.16.10 ruff format also rewrites Python code blocks in Markdown,
so make pre-commit (and the git hook running it) reformatted README.md and
the docs on every run.
Labelled column lists, row extraction plans and ORDER BY text clauses only
depend on the model, alias and selected fields, yet were rebuilt on every
query. Cache them (bounded lru caches) so repeated queries reuse them.
@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 8, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 11.74%

⚡ 4 improved benchmarks
✅ 110 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_get_column_name_from_alias[10000] 36.4 ms 32 ms +14.03%
⚡ test_get_one_wide_model[1000] 5 ms 4.5 ms +11.1%
⚡ test_get_one_wide_model[250] 5 ms 4.5 ms +10.96%
⚡ test_get_one_wide_model[500] 5 ms 4.5 ms +10.91%

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/get-query-building (312f1d6) with master (bf46168)

Open in CodSpeed

@collerek
collerek merged commit 310df0c into master Oct 8, 2026
11 checks passed
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