libsql-sqlite3: Optimize pager codec check more#2189
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes encryption codec detection by caching the encryption status at the connection level rather than checking on every pager initialization. This eliminates expensive VFS stack traversal and file lookups that previously occurred each time a pager was initialized.
Key Changes
- Added
hasCodecfield to theDbstruct to cache encryption status at the database connection level - Refactored
libsql_pager_has_codec_impltolibsql_db_has_codecwhich takes VFS and filename parameters instead of a Pager pointer - Updated
sqlite3BtreeOpenandsqlite3PagerOpenfunction signatures to accept the cachedhasCodecvalue as a parameter
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| libsql-sqlite3/src/sqliteInt.h | Added hasCodec field to Db struct to cache encryption status |
| libsql-sqlite3/src/btree.h | Updated sqlite3BtreeOpen signature to include hasCodec parameter |
| libsql-sqlite3/src/btree.c | Updated sqlite3BtreeOpen implementation to accept and pass through hasCodec parameter |
| libsql-sqlite3/src/pager.h | Updated sqlite3PagerOpen signature to include hasCodec parameter |
| libsql-sqlite3/src/pager.c | Refactored to use cached hasCodec value; removed libsql_pager_update_codec_cache function; updated libsql_pager_has_codec to call libsql_db_has_codec |
| libsql-sqlite3/src/main.c | Added forward declaration for libsql_db_has_codec; cache encryption status at database open time; pass cached value to sqlite3BtreeOpen |
| libsql-sqlite3/src/build.c | Set hasCodec to 0 for temp databases; pass cached value to sqlite3BtreeOpen |
| libsql-sqlite3/src/attach.c | Check and cache encryption status for attached databases; pass cached value to sqlite3BtreeOpen; pass 0 for memdb databases |
| libsql-sqlite3/src/vdbe.c | Pass 0 for ephemeral tables (never encrypted) to sqlite3BtreeOpen |
| libsql-sqlite3/src/test3.c | Updated test function to pass 0 to sqlite3BtreeOpen |
| libsql-ffi/bundled/src/sqlite3.c | Bundled version matching changes in individual source files |
| libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3mc_vfs.c | Renamed and refactored libsql_pager_has_codec_impl to libsql_db_has_codec with VFS and filename parameters |
| libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c | Bundled version matching changes in individual source files |
| libsql-ffi/bundled/SQLite3MultipleCiphers/src/codecext.c | Updated forward declaration; modified sqlite3_rekey_v2 to update both database and pager cached codec status after encryption changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Checking if we have a custom codec at pager open time is still plenty slow. Change the check to happen at database open time instead.
b3c1fed to
0555bdd
Compare
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.
Checking if we have a custom codec at pager open time is still plenty slow. Change the check to happen at database open time instead.