From 3afe53b04fc2db6fe9ef10fdcb1eec009f388b90 Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Tue, 27 Jan 2026 14:44:11 -0500 Subject: [PATCH] feat: add sqlite options for even faster performance --- src/cache.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/cache.ts b/src/cache.ts index 8e30717..df2db5f 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -372,6 +372,9 @@ class Cache { this.defaultExpiration = defaultExpirationHours; this.onEmojiExpired = onEmojiExpired; + // Optimize SQLite for performance + this.optimizeSQLite(); + // Initialize type-safe analytics cache this.typedAnalyticsCache = new AnalyticsCache(); @@ -384,6 +387,29 @@ class Cache { this.runMigrations(); } + /** + * Optimizes SQLite performance settings + * @private + */ + private optimizeSQLite() { + // Enable Write-Ahead Logging for better concurrency + this.db.run("PRAGMA journal_mode = WAL"); + + // NORMAL synchronous mode is faster and still safe with WAL + this.db.run("PRAGMA synchronous = NORMAL"); + + // Increase cache size to 64MB for better query performance + this.db.run("PRAGMA cache_size = -64000"); + + // Store temporary tables in memory + this.db.run("PRAGMA temp_store = MEMORY"); + + // Enable memory-mapped I/O for faster reads (256MB) + this.db.run("PRAGMA mmap_size = 268435456"); + + console.log("SQLite performance optimizations applied"); + } + /** * Initializes prepared statements for hot paths * @private -- 2.51.2