Repository navigation
Conversation
An HTML table page ran PRAGMA table_xinfo for the same table 9 times (15 as root), each a separate trip to a database thread, plus repeated foreign key, label column and FTS lookups. A warm table page now runs none of them: 77 trips to a database thread become 57, and the page is 17-22% faster against the fixtures database. table_columns(), table_column_details(), primary_keys(), foreign_keys_for_table(), fts_table(), label_column_for_table(), describe_columns() and derived_table_dependencies() share one cache on the Database object, thrown away when PRAGMA schema_version changes. That version is read again: - after any write made through the Database object, including one that fails - once in every request, so a change made by another process is seen by the next request - on every call made outside of a request The unnamed _memory database is not cached, and nor are tables in attached databases or names that match no table or view. That last rule stops table names taken from the query string, such as ?_through=, from growing the cache without limit. Immutable databases are cached without any checks. Callers get copies of the cached lists and dictionaries. derived_table_dependencies() used its own schema_version cache, which this replaces. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3102 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 81 81
Lines 14516 14579 +63
=====================================
- Misses 14516 14579 +63 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An HTML table page ran
PRAGMA table_xinfofor the same table 9 times (15 as root), each a separate trip to a database thread, plus repeated foreign key, label column and FTS lookups.?_trace=1does not show these because they go throughexecute_fn(), notexecute().A warm table page now runs none of them.
/fixtures/...facetable: trips to a database threadfacetable: statements runfacetable: median timesimple_primary_key: median timeTimes are medians of 400 warm requests through
datasette.client, three alternating runs each, on one laptop.How it works
table_columns(),table_column_details(),primary_keys(),foreign_keys_for_table(),fts_table(),label_column_for_table(),describe_columns()andderived_table_dependencies()share one cache on theDatabaseobject. It is thrown away whenPRAGMA schema_versionchanges, and that version is read again:Databaseobject (execute_write*,execute_isolated_fn), including one that failsNot cached:
_memorydatabase, where every connection is a separate database?_through=passes a table name from the query string toforeign_keys_for_table(), so without this the cache could be grown without limitImmutable databases are cached without any checks.
Callers get copies of the cached lists and dictionaries. An explicit
label_columnin configuration is still read on every call.Things to check
derived_table_dependencies()had its ownschema_versioncache in_cached_derived_table_dependencies. That is replaced by the shared one, which removes twoPRAGMA schema_versiontrips per page.tests/test_fts_permissions.pyand one intests/test_internals_database.pyasserted on that removed private attribute. They now assert the same guarantee, that a failed refresh leaves nothing cached, against the new cache.Tests
tests/test_schema_cache.pycovers each of the cases above with 0, 1 and 3 SQL threads. The tests fail if write invalidation, the per-request re-check or the copying is removed.🤖 Generated with Claude Code