⚡ Bolt: optimize SessionManager initialization and queries#58
⚡ Bolt: optimize SessionManager initialization and queries#58charles-forsyth wants to merge 1 commit intomainfrom
Conversation
This commit implements several performance improvements to the SessionManager: - Resolves the N+1 query problem in list_sessions using a LEFT JOIN to fetch parent info. - Batches UPDATE statements for crashed sessions into a single query. - Adds database indexes to interaction_id, parent_id, and updated_at for faster lookups. - Implements a class-level cache to skip redundant database initialization/migrations. A new performance test suite (tests/test_performance.py) is included to verify these improvements. Co-authored-by: charles-forsyth <54458298+charles-forsyth@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. |
💡 What:
Optimized the
SessionManagerclass to reduce database overhead and resolve an N+1 query problem in the session listing logic.🎯 Why:
list_sessionswas performing a separate query for every running child session to check its parent's status.UPDATEandcommit()calls were being made in a loop for crashed sessions._init_db(including migrations and PRAGMAs) was running every time aSessionManagerwas instantiated, which happens frequently in recursive research.interaction_id,parent_id, andupdated_at.📊 Impact:
list_sessionsquery count from O(N) to O(1) for fetching session data.list_sessionsupdate count from O(M) to O(1) for marking crashed sessions.🔬 Measurement:
Verified using
tests/test_performance.py, which uses a proxy connection to count exact database queries. Results:list_sessionsquery count for 5 child sessions: 6 -> 1list_sessionsupdate count for 5 crashed sessions: 5 -> 1PR created automatically by Jules for task 5935941829814978723 started by @charles-forsyth