Skip to content

Conversation

@penberg
Copy link
Collaborator

@penberg penberg commented Nov 7, 2025

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.

@penberg penberg requested a review from Copilot November 7, 2025 08:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hasCodec field to the Db struct to cache encryption status at the database connection level
  • Refactored libsql_pager_has_codec_impl to libsql_db_has_codec which takes VFS and filename parameters instead of a Pager pointer
  • Updated sqlite3BtreeOpen and sqlite3PagerOpen function signatures to accept the cached hasCodec value 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.
@penberg penberg force-pushed the optimize-codec-check-more branch from b3c1fed to 0555bdd Compare November 7, 2025 08:18
@penberg penberg enabled auto-merge November 7, 2025 08:19
@penberg penberg added this pull request to the merge queue Nov 7, 2025
Merged via the queue into main with commit 49842d1 Nov 7, 2025
19 of 20 checks passed
@penberg penberg deleted the optimize-codec-check-more branch November 7, 2025 08:49
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