From 68c8588cd55ece55119c310bbbc13a9586ead51c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 8 Sep 2026 08:30:33 +0000 Subject: [PATCH] perf(sqlite): use prepare_cached for database queries Replaces conn.execute() and conn.prepare() with conn.prepare_cached() in the sqlite module. This leverages rusqlite's built-in LRU statement cache to avoid recompiling SQL statements on every loop iteration, resolving N+1 compilation overheads during bulk operations. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- stdlib/src/sqlite.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index c7d8f769..487d44da 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -93,7 +93,14 @@ impl StdlibRegistry { CONNECTIONS.with(|m| { let mut map = m.borrow_mut(); if let Some(conn) = map.get_mut(&id) { - conn.execute(&sql, rusqlite::params_from_iter(params)) + let mut stmt = conn.prepare_cached(&sql).map_err(|e| { + RuntimeError::new( + RuntimeErrorKind::InvalidOperation(e.to_string()), + None, + None, + ) + })?; + stmt.execute(rusqlite::params_from_iter(params)) .map_err(|e| { RuntimeError::new( RuntimeErrorKind::InvalidOperation(e.to_string()), @@ -161,7 +168,7 @@ impl StdlibRegistry { let rows = CONNECTIONS.with(|m| { let mut map = m.borrow_mut(); if let Some(conn) = map.get_mut(&id) { - let mut stmt = conn.prepare(&sql).map_err(|e| { + let mut stmt = conn.prepare_cached(&sql).map_err(|e| { RuntimeError::new( RuntimeErrorKind::InvalidOperation(e.to_string()), None,