Skip to content

perf: cache list_windows and skip redundant project scans#74

Open
frankjoshua wants to merge 1 commit intosix-ddc:mainfrom
frankjoshua:perf/cache-list-windows
Open

perf: cache list_windows and skip redundant project scans#74
frankjoshua wants to merge 1 commit intosix-ddc:mainfrom
frankjoshua:perf/cache-list-windows

Conversation

@frankjoshua
Copy link
Copy Markdown

Summary

  • Add 1-second TTL cache to TmuxManager.list_windows() — multiple callers within the same second share one libtmux query instead of each creating a fresh libtmux.Server() connection
  • SessionMonitor.check_for_updates() now uses stored file paths for already-tracked sessions, only running the expensive scan_projects() directory walk when new untracked sessions appear

Problem

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:

  1. Status poll loop (every 1s) → find_window_by_id()list_windows()
  2. Session monitor (every 2s) → scan_projects()_get_active_cwds()list_windows()
  3. Message queue → _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

  • Verify existing tests pass
  • Monitor CPU usage before/after with multiple active sessions
  • Confirm new sessions are still discovered (scan_projects runs for untracked sessions)
  • Confirm status polling still works normally

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant