⚡ Bolt: Optimize SessionManager database operations#57
⚡ Bolt: Optimize SessionManager database operations#57charles-forsyth wants to merge 1 commit intomainfrom
Conversation
This PR implements several performance optimizations for the SessionManager: 1. Avoids redundant DB initialization using a class-level cache. 2. Resolves an N+1 query problem in list_sessions by using a JOIN. 3. Batches status updates for crashed sessions to reduce disk I/O. 4. Adds indexes for frequently queried columns (interaction_id, parent_id, updated_at). Impact: - Redundant initializations: 3 queries -> 0 queries. - list_sessions (6 sessions): 12 queries -> 2 queries. - Faster lookups and sorting as history grows. Co-authored-by: charles-forsyth <[email protected]>
|
👋 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. |
⚡ Bolt: Optimize SessionManager database operations
💡 What
Implemented a series of optimizations in the
SessionManagerclass to streamline database operations:_initialized_dbsto track and skip unnecessary schema checks and migrations for databases already processed in the current process.list_sessionsto use aLEFT JOINon the sessions table itself, fetching parent session information in the primary query instead of executing a separate query for each child session.UPDATEstatements for crashed sessions with a single batchedWHERE id IN (...)query, significantly reducing disk I/O and transaction overhead.interaction_id,parent_id, andupdated_atto ensure fast lookups, hierarchical traversal, and sorted listings.🎯 Why
The
SessionManagerwas performing several inefficient database operations that slowed down the CLI (especially thelistcommand) and the recursive research process (where many agent instances are created). EachPRAGMAcheck and individualUPDATEcommit added latency.📊 Impact
Measured using benchmark scripts:
SessionManagerinstance.list_sessionsPerformance: For a typical scenario with 6 sessions (1 parent, 5 children), queries were reduced from 12 down to 2.🔬 Measurement
Verified using
bench_init.pyandbench_list_sessions.py(which proxysqlite3to count queries) and by running the full test suite withuv run pytest.PR created automatically by Jules for task 6751822011168121911 started by @charles-forsyth