⚡ Bolt: Optimize AdaptiveMemory with persistent connections and WAL - #25
⚡ Bolt: Optimize AdaptiveMemory with persistent connections and WAL#25Rohith-Shimori wants to merge 1 commit into
Conversation
Refactored `AdaptiveMemory` to use a persistent SQLite connection and enabled Write-Ahead Logging (WAL) mode. This reduces the overhead of opening and closing connections for every operation. Improvements: - Uses `threading.RLock` to ensure thread-safe access to the shared connection. - Enables `PRAGMA journal_mode=WAL` for better concurrency. - Enables `PRAGMA synchronous=NORMAL` for faster writes. - Added `db_path` argument to `__init__` for better testability. - Updated `.gitignore` to exclude WAL temporary files. Benchmark Results: - Operation time reduced from ~0.54s to ~0.02s for 100 ops (~23x speedup). Co-authored-by: Rohith-Shimori <228351330+Rohith-Shimori@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR optimizes the
AdaptiveMemoryclass by replacing per-method SQLite connections with a persistent, thread-safe connection pool (single shared connection with locking).Why:
The previous implementation opened and closed a new SQLite connection for every single memory operation (add, get, update, etc.). This introduced significant I/O and locking overhead.
What:
_get_connection()to manage a lazy-loaded persistent connection.threading.RLockto guard all database access, ensuring thread safety even withcheck_same_thread=False.PRAGMA journal_mode=WAL(Write-Ahead Logging) which significantly improves write performance and concurrency.__init__to accept an optionaldb_pathto allow isolated testing without touching the production database.*.db-waland*.db-shmto.gitignore.Impact:
PR created automatically by Jules for task 12668868580798505927 started by @Rohith-Shimori