From 061c2a5f43ccfcdbe0bf04a9a5203f4fc31fc63b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 8 Apr 2026 13:38:45 +0900 Subject: [PATCH] check stmtCacheSize before acquiring mutex in takeCachedStmt stmtCacheSize is immutable after connection open, so checking it before the lock avoids mutex overhead when cache is not enabled. --- sqlite3.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlite3.go b/sqlite3.go index ef06c85..5861a2f 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -1906,14 +1906,14 @@ func (c *SQLiteConn) dbConnOpen() bool { } func (c *SQLiteConn) takeCachedStmt(query string) *SQLiteStmt { - if c == nil || query == "" { + if c == nil || query == "" || c.stmtCacheSize <= 0 { return nil } c.mu.Lock() defer c.mu.Unlock() - if c.db == nil || c.stmtCacheSize <= 0 { + if c.db == nil { return nil } stmts := c.stmtCache[query]