From 0db63fc5761bf53f10cacadd1cbe841305240802 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 31 Aug 2026 17:42:27 +0000 Subject: [PATCH] feat(hotpath): fill rusqlite-runtime execute/query gaps Co-authored-by: Zack Jackson --- .../tracedecay-rusqlite-runtime/src/connection/mod.rs | 1 + .../tracedecay-rusqlite-runtime/src/exact_sql/mod.rs | 9 +++++++++ .../src/reader/pool/lease.rs | 8 ++++++++ .../tracedecay-rusqlite-runtime/src/reader/pool/mod.rs | 3 +++ .../src/remote/recovery_authority.rs | 10 ++++++++++ .../src/repository/configuration.rs | 3 +++ .../src/repository/diagnostics.rs | 5 +++++ .../src/repository/project.rs | 7 +++++++ .../src/repository/remote.rs | 3 +++ .../src/repository/retrieval_anchor.rs | 4 ++++ crates/tracedecay-rusqlite-runtime/src/work/sql.rs | 1 + crates/tracedecay-rusqlite-runtime/src/writer.rs | 2 ++ 12 files changed, 56 insertions(+) diff --git a/crates/tracedecay-rusqlite-runtime/src/connection/mod.rs b/crates/tracedecay-rusqlite-runtime/src/connection/mod.rs index 9c6ff8333d..48c5353952 100644 --- a/crates/tracedecay-rusqlite-runtime/src/connection/mod.rs +++ b/crates/tracedecay-rusqlite-runtime/src/connection/mod.rs @@ -226,6 +226,7 @@ impl OpenedDatabaseFile { Ok(()) } + #[hotpath::measure(label = "rusqlite.connection.verify_identity")] pub(crate) fn verify_connection( &self, _connection: &Connection, diff --git a/crates/tracedecay-rusqlite-runtime/src/exact_sql/mod.rs b/crates/tracedecay-rusqlite-runtime/src/exact_sql/mod.rs index 498372d1a0..7afabc5648 100644 --- a/crates/tracedecay-rusqlite-runtime/src/exact_sql/mod.rs +++ b/crates/tracedecay-rusqlite-runtime/src/exact_sql/mod.rs @@ -335,6 +335,7 @@ impl ExactSqlHandle { } /// Checkpoints and truncates the WAL on the serialized writer connection. + #[hotpath::measure(label = "rusqlite.exact_sql.checkpoint_wal_truncate")] pub fn checkpoint_wal_truncate(&self) -> Result { let (reply, response) = mpsc::sync_channel(1); self.writer @@ -365,6 +366,7 @@ impl ExactSqlHandle { /// anything reports a typed no-op instead of [`ExactSqlError::WriterUnavailable`]; /// a reader release that *errored* is never a no-op — it propagates so /// the maintenance caller's degraded log fires. + #[hotpath::measure(label = "rusqlite.exact_sql.release_memory")] pub fn release_connection_memory(&self) -> Result { let readers = (self.release_reader_memory)()?; let writer = if self.writer.is_some() { @@ -381,6 +383,7 @@ impl ExactSqlHandle { } /// Enables incremental auto-vacuum through its fixed maintenance rebuild. + #[hotpath::measure(label = "rusqlite.exact_sql.repair_auto_vacuum")] pub fn repair_incremental_auto_vacuum(&self) -> Result<(), ExactSqlError> { let (reply, response) = mpsc::sync_channel(1); self.writer @@ -628,6 +631,7 @@ impl ExactSqlTransaction { } } + #[hotpath::measure(label = "rusqlite.exact_sql.txn_commit")] pub fn commit(mut self) -> Result { let sender = self .commands @@ -642,6 +646,7 @@ impl ExactSqlTransaction { .map_err(|_| transaction_terminal_error(&self.expired))? } + #[hotpath::measure(label = "rusqlite.exact_sql.txn_rollback")] pub fn rollback(mut self) -> Result { let sender = self .commands @@ -660,6 +665,7 @@ impl ExactSqlTransaction { self.dispatch_with_policy(request, ExecutionPolicy::Bounded) } + #[hotpath::measure(label = "rusqlite.exact_sql.txn_dispatch")] fn dispatch_with_policy( &self, request: SqlRequest, @@ -823,6 +829,7 @@ fn execute_statement( }) } +#[hotpath::measure(label = "rusqlite.exact_sql.attach_db")] fn attach_database( connection: &Connection, attachment: &ExactSqlAttachment, @@ -851,6 +858,7 @@ fn attach_database( ) } +#[hotpath::measure(label = "rusqlite.exact_sql.detach_db")] fn detach_database( connection: &Connection, database_name: &str, @@ -878,6 +886,7 @@ fn detach_database( ) } +#[hotpath::measure(label = "rusqlite.exact_sql.execute_batch")] fn execute_batch(connection: &Connection, sql: &str) -> Result { let before = connection.total_changes(); connection diff --git a/crates/tracedecay-rusqlite-runtime/src/reader/pool/lease.rs b/crates/tracedecay-rusqlite-runtime/src/reader/pool/lease.rs index a1948b178a..8d08e78a4e 100644 --- a/crates/tracedecay-rusqlite-runtime/src/reader/pool/lease.rs +++ b/crates/tracedecay-rusqlite-runtime/src/reader/pool/lease.rs @@ -125,6 +125,7 @@ impl ReaderLease { self.checkout.retire = true; } + #[hotpath::measure(label = "rusqlite.reader_lease.begin_snapshot")] pub fn begin_snapshot(&mut self) -> Result, ReaderWorkerError> { if self.snapshot_active { return Err(ReaderWorkerError::SnapshotAlreadyActive); @@ -134,6 +135,7 @@ impl ReaderLease { Ok(SnapshotLease { lease: self }) } + #[hotpath::measure(label = "rusqlite.reader_lease.execute")] pub(crate) fn execute_active_raw( &mut self, request: RuntimeReadRequestV1, @@ -161,6 +163,7 @@ impl ReaderLease { .map_err(map_worker_error) } + #[hotpath::measure(label = "rusqlite.reader_lease.exact_sql_query")] pub(super) fn execute_exact_sql_query( &mut self, statement: ExactSqlStatement, @@ -182,6 +185,7 @@ impl ReaderLease { .execute_exact_sql_query(statement) } + #[hotpath::measure(label = "rusqlite.reader_lease.begin_exact_sql_snapshot")] pub(super) fn begin_exact_sql_snapshot(&mut self) -> Result<(), ExactSqlError> { if self.snapshot_active { return Err(ExactSqlError::ReaderUnavailable( @@ -197,6 +201,7 @@ impl ReaderLease { self.checkout.worker.client.pin_exact_sql() } + #[hotpath::measure(label = "rusqlite.reader_lease.exact_sql_snapshot_query")] pub(super) fn execute_active_exact_sql_query( &mut self, statement: ExactSqlStatement, @@ -212,6 +217,7 @@ impl ReaderLease { .execute_exact_sql_query(statement) } + #[hotpath::measure(label = "rusqlite.reader_lease.store_size")] pub(super) fn read_store_size( &mut self, reply_bound: std::time::Duration, @@ -234,6 +240,7 @@ impl ReaderLease { .map_err(map_worker_error) } + #[hotpath::measure(label = "rusqlite.reader_lease.table_sizes")] pub(super) fn read_table_sizes( &mut self, reply_bound: std::time::Duration, @@ -274,6 +281,7 @@ impl ReaderLease { .map_err(|error| ReaderAcquireError::Worker(ReaderWorkerError::Storage(error))) } + #[hotpath::measure(label = "rusqlite.reader_lease.finish_snapshot")] fn finish_snapshot(&mut self) { if !self.snapshot_active { return; diff --git a/crates/tracedecay-rusqlite-runtime/src/reader/pool/mod.rs b/crates/tracedecay-rusqlite-runtime/src/reader/pool/mod.rs index 3eeb7d77ab..c6950f6ef7 100644 --- a/crates/tracedecay-rusqlite-runtime/src/reader/pool/mod.rs +++ b/crates/tracedecay-rusqlite-runtime/src/reader/pool/mod.rs @@ -491,6 +491,7 @@ impl ReaderPool { /// Each worker connection keeps its own SQLite cache. Dispatching /// `PRAGMA shrink_memory` through the writer actor would shrink the /// wrong connection (or fail when no writer is attached). + #[hotpath::measure(label = "rusqlite.reader_pool.release_memory")] pub(crate) fn release_connection_memory(&self) -> Result { let (lifecycle, clients) = { let state = self @@ -906,6 +907,7 @@ impl ReaderPool { /// Opportunistically retire burst workers. This method performs no sleep; /// tests and maintenance callers can supply a deterministic monotonic time. + #[hotpath::measure(label = "rusqlite.reader_pool.retire_idle")] pub fn retire_idle_at(&self, now: Instant) -> usize { let mut retired = Vec::new(); { @@ -944,6 +946,7 @@ impl ReaderPool { retired.len() } + #[hotpath::measure(label = "rusqlite.reader_pool.add_worker")] fn add_idle_worker(&self, lane: ReaderLane) -> Result<(), ReaderStartError> { let spawned = worker::spawn( self.inner.locator.clone(), diff --git a/crates/tracedecay-rusqlite-runtime/src/remote/recovery_authority.rs b/crates/tracedecay-rusqlite-runtime/src/remote/recovery_authority.rs index 4471b89323..5a9add3302 100644 --- a/crates/tracedecay-rusqlite-runtime/src/remote/recovery_authority.rs +++ b/crates/tracedecay-rusqlite-runtime/src/remote/recovery_authority.rs @@ -142,6 +142,7 @@ impl RemoteRecoverySqliteAuthorityV1 { /// Publishes the authority-store value used by every later recovery CAS. /// A lower epoch, or a different writer at the same epoch, is rejected. + #[hotpath::measure(label = "rusqlite.recovery.publish_authority")] pub fn publish_authority( &self, authority: &CurrentRemoteAuthorityV1, @@ -191,6 +192,7 @@ impl RemoteRecoverySqliteAuthorityV1 { /// becomes available. The original admitted request and caller binding are /// journaled before the write gate is visible, so recovery never depends /// on an API caller retrying. + #[hotpath::measure(label = "rusqlite.recovery.reconcile_promotions")] pub fn reconcile_interrupted_promotions( &self, project_id: &tracedecay_domain::ProjectId, @@ -224,6 +226,7 @@ impl RemoteRecoverySqliteAuthorityV1 { Ok(reconciled) } + #[hotpath::measure(label = "rusqlite.recovery.seed_authority")] fn ensure_authority_seeded( &self, expected: &RecoveryAuthorityExpectationV1, @@ -256,6 +259,7 @@ impl RemoteRecoverySqliteAuthorityV1 { .map_err(map_store_error) } + #[hotpath::measure(label = "rusqlite.recovery.promotion_pending")] fn promotion_is_pending( &self, operation_id: &str, @@ -278,6 +282,7 @@ impl RemoteRecoverySqliteAuthorityV1 { } #[allow(clippy::too_many_arguments)] + #[hotpath::measure(label = "rusqlite.recovery.execute_operation")] fn execute_operation( &self, kind: &'static str, @@ -404,6 +409,7 @@ impl RemoteRecoveryControlPortV1 for RecoveryReconciliationControlV1 { } impl RemoteSqliteStorageV1 { + #[hotpath::measure(label = "rusqlite.recovery.load_writer")] pub fn recovery_writer( &self, expected: &RecoveryAuthorityExpectationV1, @@ -426,6 +432,7 @@ impl RemoteSqliteStorageV1 { Ok(writer) } + #[hotpath::measure(label = "rusqlite.recovery.load_writer_lineage")] pub fn recovery_writer_for_lineage( &self, expected: &RecoveryAuthorityExpectationV1, @@ -517,6 +524,7 @@ impl RemoteRecoveryOperationPortV1 for RemoteRecoverySqliteAuthorityV1 { ) } + #[hotpath::measure(label = "rusqlite.recovery.promote")] fn promote( &self, request: &RemoteProtocolRequestV1, @@ -652,6 +660,7 @@ impl RemoteRecoveryOperationPortV1 for RemoteRecoverySqliteAuthorityV1 { } } +#[hotpath::measure(label = "rusqlite.recovery.authority_state")] fn available_authority_state( handle: &ExactSqlHandle, expected: &RecoveryAuthorityExpectationV1, @@ -815,6 +824,7 @@ fn validate_sink_inventory(sink_ids: &[String]) -> Result<(), RemoteRecoveryOper Ok(()) } +#[hotpath::measure(label = "rusqlite.recovery.persist_sink_receipts")] fn persist_sink_receipts( handle: &ExactSqlHandle, operation_id: &str, diff --git a/crates/tracedecay-rusqlite-runtime/src/repository/configuration.rs b/crates/tracedecay-rusqlite-runtime/src/repository/configuration.rs index e5bf27e2df..50ef5ea60d 100644 --- a/crates/tracedecay-rusqlite-runtime/src/repository/configuration.rs +++ b/crates/tracedecay-rusqlite-runtime/src/repository/configuration.rs @@ -24,6 +24,7 @@ const ACTIVATION_NOT_RECORDED: &str = "not_recorded_by_configuration_store_v1"; pub struct ConfigurationExecutor; impl ConfigurationExecutor { + #[hotpath::measure(label = "rusqlite.configuration.write")] pub fn execute_write( &mut self, savepoint: &Savepoint<'_>, @@ -78,6 +79,7 @@ impl ConfigurationExecutor { Ok(()) } + #[hotpath::measure(label = "rusqlite.configuration.read")] pub fn execute_read( &mut self, snapshot: &Transaction<'_>, @@ -138,6 +140,7 @@ fn current_revision_id(connection: &rusqlite::Connection) -> rusqlite::Result, revision: &ConfigurationRevisionRecordV1, diff --git a/crates/tracedecay-rusqlite-runtime/src/repository/diagnostics.rs b/crates/tracedecay-rusqlite-runtime/src/repository/diagnostics.rs index a04f520f8e..89cde488ea 100644 --- a/crates/tracedecay-rusqlite-runtime/src/repository/diagnostics.rs +++ b/crates/tracedecay-rusqlite-runtime/src/repository/diagnostics.rs @@ -26,6 +26,7 @@ const CLEARED: &str = DIAGNOSTIC_STATE_CLEARED; pub struct DiagnosticExecutor; impl DiagnosticExecutor { + #[hotpath::measure(label = "rusqlite.diagnostics.write")] pub fn execute_write( &mut self, savepoint: &Savepoint<'_>, @@ -106,6 +107,7 @@ impl DiagnosticExecutor { /// lanes and must stay so: clearing marks records a newer clean generation /// replaced wholesale, while supersession preserves a walkable chain from /// a prior finding to its logical successor. + #[hotpath::measure(label = "rusqlite.diagnostics.supersede")] pub fn execute_supersession( &mut self, savepoint: &Savepoint<'_>, @@ -129,6 +131,7 @@ impl DiagnosticExecutor { Ok(transitioned as u64) } + #[hotpath::measure(label = "rusqlite.diagnostics.read")] pub fn execute_read( &mut self, snapshot: &Transaction<'_>, @@ -197,6 +200,7 @@ impl DiagnosticExecutor { /// The walk stops at a current, cleared, or missing successor. An anchor /// already visited also stops the walk, so a cyclic `state_generation` graph /// cannot spin here. +#[hotpath::measure(label = "rusqlite.diagnostics.chain_walk")] fn read_supersession_chain( connection: &rusqlite::Connection, anchor: &RetrievalAnchorId, @@ -266,6 +270,7 @@ fn read_logical_successor( Ok(records.pop()) } +#[hotpath::measure(label = "rusqlite.diagnostics.insert_record")] fn insert_record( savepoint: &Savepoint<'_>, record: &GenerationDiagnosticV1, diff --git a/crates/tracedecay-rusqlite-runtime/src/repository/project.rs b/crates/tracedecay-rusqlite-runtime/src/repository/project.rs index 9fc72c9320..4ea29a9bf0 100644 --- a/crates/tracedecay-rusqlite-runtime/src/repository/project.rs +++ b/crates/tracedecay-rusqlite-runtime/src/repository/project.rs @@ -26,6 +26,7 @@ pub struct ProjectExecutor { } impl ProjectExecutor { + #[hotpath::measure(label = "rusqlite.project.fact_write")] pub fn execute_fact_write( &mut self, savepoint: &Savepoint<'_>, @@ -34,6 +35,7 @@ impl ProjectExecutor { self.fact.execute_write(savepoint, batch) } + #[hotpath::measure(label = "rusqlite.project.observation_write")] pub fn execute_observation_write( &mut self, savepoint: &Savepoint<'_>, @@ -54,6 +56,7 @@ impl ProjectExecutor { Ok(()) } + #[hotpath::measure(label = "rusqlite.project.observation_batch")] pub fn execute_observation_batch( &mut self, savepoint: &Savepoint<'_>, @@ -65,6 +68,7 @@ impl ProjectExecutor { Ok(()) } + #[hotpath::measure(label = "rusqlite.project.remote_observation_replay")] pub fn execute_remote_observation_replay( &mut self, savepoint: &Savepoint<'_>, @@ -83,6 +87,7 @@ impl ProjectExecutor { install_writer_fence(savepoint, install) } + #[hotpath::measure(label = "rusqlite.project.observation_cursor_advance")] pub fn execute_observation_cursor_advance( &mut self, savepoint: &Savepoint<'_>, @@ -113,6 +118,7 @@ impl ProjectExecutor { .map(|_| ()) } + #[hotpath::measure(label = "rusqlite.project.evidence_assembly_write")] pub fn execute_evidence_assembly_write( &mut self, savepoint: &Savepoint<'_>, @@ -184,6 +190,7 @@ impl ProjectExecutor { .execute_derivative_write(savepoint, derivative) } + #[hotpath::measure(label = "rusqlite.project.read")] pub fn execute_read( &mut self, snapshot: &Transaction<'_>, diff --git a/crates/tracedecay-rusqlite-runtime/src/repository/remote.rs b/crates/tracedecay-rusqlite-runtime/src/repository/remote.rs index 022aa58bbd..b66d300dff 100644 --- a/crates/tracedecay-rusqlite-runtime/src/repository/remote.rs +++ b/crates/tracedecay-rusqlite-runtime/src/repository/remote.rs @@ -3,6 +3,7 @@ use tracedecay_store::{RemoteObservationReplayWriteV1, RemoteWriterFenceInstallV use super::support::{encode, invalid}; +#[hotpath::measure(label = "rusqlite.remote.fence_verify_seed")] pub(super) fn verify_and_seed_writer_fence( savepoint: &Savepoint<'_>, write: &RemoteObservationReplayWriteV1, @@ -44,6 +45,7 @@ pub(super) fn verify_and_seed_writer_fence( Ok(()) } +#[hotpath::measure(label = "rusqlite.remote.observation_event_persist")] pub(super) fn persist_remote_observation_event( savepoint: &Savepoint<'_>, write: &RemoteObservationReplayWriteV1, @@ -133,6 +135,7 @@ pub(super) fn persist_remote_observation_event( Ok(()) } +#[hotpath::measure(label = "rusqlite.remote.fence_install")] pub(super) fn install_writer_fence( savepoint: &Savepoint<'_>, install: &RemoteWriterFenceInstallV1, diff --git a/crates/tracedecay-rusqlite-runtime/src/repository/retrieval_anchor.rs b/crates/tracedecay-rusqlite-runtime/src/repository/retrieval_anchor.rs index 0b8a26bab9..96aedc8877 100644 --- a/crates/tracedecay-rusqlite-runtime/src/repository/retrieval_anchor.rs +++ b/crates/tracedecay-rusqlite-runtime/src/repository/retrieval_anchor.rs @@ -12,6 +12,7 @@ use super::support::{decode, encode, idempotent_insert, invalid}; pub struct RetrievalAnchorExecutor; impl RetrievalAnchorExecutor { + #[hotpath::measure(label = "rusqlite.retrieval_anchor.disposition_write")] pub fn execute_disposition_write( &mut self, savepoint: &Savepoint<'_>, @@ -75,6 +76,7 @@ impl RetrievalAnchorExecutor { Ok(()) } + #[hotpath::measure(label = "rusqlite.retrieval_anchor.derivative_write")] pub fn execute_derivative_write( &mut self, savepoint: &Savepoint<'_>, @@ -112,6 +114,7 @@ impl RetrievalAnchorExecutor { ) } + #[hotpath::measure(label = "rusqlite.retrieval_anchor.read")] pub fn execute_read( &mut self, snapshot: &Transaction<'_>, @@ -206,6 +209,7 @@ fn current_state( .map(|record| record.map(|record| record.state())) } +#[hotpath::measure(label = "rusqlite.retrieval_anchor.current_record")] fn current_record( connection: &rusqlite::Connection, anchor_id: &RetrievalAnchorId, diff --git a/crates/tracedecay-rusqlite-runtime/src/work/sql.rs b/crates/tracedecay-rusqlite-runtime/src/work/sql.rs index 7754fddb6a..f60804a71f 100644 --- a/crates/tracedecay-rusqlite-runtime/src/work/sql.rs +++ b/crates/tracedecay-rusqlite-runtime/src/work/sql.rs @@ -51,6 +51,7 @@ impl RegisteredWorkQuery for ExactSqlTransaction { } } +#[hotpath::measure(label = "rusqlite.work.query")] pub(crate) fn registered_work_query( source: &impl RegisteredWorkQuery, sql: &str, diff --git a/crates/tracedecay-rusqlite-runtime/src/writer.rs b/crates/tracedecay-rusqlite-runtime/src/writer.rs index 110a5fb2f2..9e27511035 100644 --- a/crates/tracedecay-rusqlite-runtime/src/writer.rs +++ b/crates/tracedecay-rusqlite-runtime/src/writer.rs @@ -795,6 +795,7 @@ impl PersistentWriter { Ok(outcome) } + #[hotpath::measure(label = "rusqlite.writer.bounded_incremental_vacuum", future = true)] pub async fn bounded_incremental_vacuum( &self, max_pages: u32, @@ -855,6 +856,7 @@ impl PersistentWriter { .await } + #[hotpath::measure(label = "rusqlite.writer.enqueue_online_backup", future = true)] async fn enqueue_online_backup( &self, destination: PathBuf,