Subject: [PATCH] database: Use SQLite in Multi-thread mode.
From: Clément Lassieur <[email-masked]>
To: [email-masked]
Date: Thu, 19 Jul 2018 12:54:57 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

This disables mutexing on database connection and prepared statement objects,
thus making us responsible for serializing access to database connections and
prepared statements.  It may result in a performance improvement.

* src/cuirass/database.scm (db-init, db-open): Pass the SQLITE_OPEN_NOMUTEX
flag to SQLITE-OPEN.
---
 src/cuirass/database.scm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index a84d0fa..6bf3bc4 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -195,7 +195,8 @@ database object."
     (format (current-error-port) "Removing leftover database ~a~%" db-name)
     (delete-file db-name))
   (let ((db (sqlite-open db-name (logior SQLITE_OPEN_CREATE
-                                         SQLITE_OPEN_READWRITE))))
+                                         SQLITE_OPEN_READWRITE
+                                         SQLITE_OPEN_NOMUTEX))))
     (db-load db schema)
     (db-set-schema-version db (latest-db-schema-version))
     db))
@@ -222,7 +223,9 @@ database object."
   ;; avoid SQLITE_LOCKED errors when we have several readers:
   ;; <https://www.sqlite.org/wal.html>.
   (set-db-options (if (file-exists? db)
-                      (db-upgrade (sqlite-open db SQLITE_OPEN_READWRITE))
+                      (db-upgrade
+                       (sqlite-open db (logior SQLITE_OPEN_READWRITE
+                                               SQLITE_OPEN_NOMUTEX)))
                       (db-init db))))
 
 (define (db-close db)
-- 
2.18.0