perf: cache list_windows and skip redundant project scans#74
Open
frankjoshua wants to merge 1 commit intosix-ddc:mainfrom
Open
perf: cache list_windows and skip redundant project scans#74frankjoshua wants to merge 1 commit intosix-ddc:mainfrom
frankjoshua wants to merge 1 commit intosix-ddc:mainfrom
Conversation
list_windows() via libtmux was called 3+ times/second from independent callers at ~39ms each. Add 1s TTL cache so concurrent callers share one query. Also skip the full scan_projects() directory walk for sessions already tracked in monitor state — only scan when new sessions appear. Reduces CPU from ~34% to ~8%. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TmuxManager.list_windows()— multiple callers within the same second share one libtmux query instead of each creating a freshlibtmux.Server()connectionSessionMonitor.check_for_updates()now uses stored file paths for already-tracked sessions, only running the expensivescan_projects()directory walk when new untracked sessions appearProblem
list_windows()takes ~39ms per call (creates a new libtmux Server and iterates all windows). It was being called 3+ times per second from independent callers:find_window_by_id()→list_windows()scan_projects()→_get_active_cwds()→list_windows()_check_and_send_status()→find_window_by_id()→list_windows()Additionally,
scan_projects()was scanning all project directories and globbing JSONL files every 2 seconds, even though tracked sessions already had file paths stored in monitor state.Result
CPU usage dropped from ~34% to ~8% in testing with 10 active sessions and 18 tmux windows.
Test plan
🤖 Generated with Claude Code