CPU Usage Regression: v0.9.12 (idle) → v0.9.13 (moderate) → v0.10.0 (heavy)
Platform: FreeBSD 15.0 (x86-64) Binaries analyzed:
cw00912— Codewhale v0.9.12 (82 MB ELF, dynamically linked)cw00913— Codewhale v0.9.13 (89 MB ELF, dynamically linked)cw01000— Codewhale v0.10.0 (90 MB ELF, dynamically linked)
All three binaries are Rust executables (ELF 64-bit LSB pie, compiled for FreeBSD).
Observed Behavior
| Version | Idle CPU (top) | Threads | event_loop.rs size |
|---|---|---|---|
| v0.9.12 | ~1% (uwait) | 17 | ~4264 lines |
| v0.9.13 | ~5-8% | ~25-30 | ~7323 lines |
| v0.10.0 | ~8-15% | ~30+ | ~7323 + dispatch |
uwait state = waiting on user event (interrupt-driven). Later versions show active polling.
Root Cause Analysis
Between v0.9.12 and v0.9.13 (+7 MB, major CPU increase)
The event loop grew from ~4264 to ~7323 lines (+70%). Multiple background polling workers were added:
@-mention discovery worker (
crates/tui/src/tui/mention_completion.rs)- Background thread
codewhale-mention-discoverythat continuously scans the workspace for @-mention candidates - Polls filesystem even when user is idle
- Background thread
LSP (Language Server Protocol) integration
- New modules:
crates/tui/src/lsp/mod.rs,lsp/client.rs,core/engine/lsp_hooks.rs,tools/lsp.rs - Spawns
lsp-writer,lsp-reader,lsp-dispatcherthreads - Supports rust-analyzer, gopls, typescript-language-server, clangd, etc.
- Background language analysis runs continuously, even with no files open
- New modules:
Runtime event tap / store monitoring
runtime event tap lagged; a store-failure notice may have been missed- Polls runtime store state periodically
Thread goal stall monitoring
failed to initialize durable goal stall schema- Tracks
stalled_ms,pause_reason,repeated_gap_count,last_gap_fingerprint - Continuously checks if threads are stalled
Engine tick & telemetry bucket aggregation
engineTickincrements every iteration, bucket aggregation every 12 ticks- Telemetry events with timestamps, agent IDs, tool tracking
Session persistence polling
- Polls
session_index.jsonlfor job status changes - Periodic SQLite queries for thread status (
SELECT id, rollout_path, preview...)
- Polls
File frecency tracking (
crates/tui/src/tui/file_frecency.rs)- Background tracking of file access frequency
Models.dev live fetch (
crates/tui/src/models_dev_live.rs)- Periodic HTTP fetch of model catalog
Between v0.9.13 and v0.10.0 (+1 MB, additional CPU)
Fleet manager (
crates/tui/src/fleet/manager.rs:1338)- Fleet worker coordination with active polling
Fleet worker coordination is not currently admissible
Background hooks
background hooks cannot deny tool calls because they exit immediately with no result- Hooks run for every tool call/event
Dispatch completion mailbox
dispatch completion mailbox is unavailable/full/closed- Polls mailbox for dispatch results
VM thread management
VM thread exited without reporting a resultVM admission gate closed
Agent profile permissions (
AgentProfilePermissionsToml)
Architectural Shift
v0.9.12 uses an interrupt-driven event loop: it sleeps on kevent/kqueue and wakes only on user input. The TUI event loop had ~4264 lines.
v0.9.13+ switches to a polling-driven architecture: background workers wake periodically regardless of user activity. The event loop grew to ~7323 lines with runtime tap lag detection, persistence health checks, and session validation — all running on every iteration.
Impact
- Significant battery drain on laptops
- Unnecessary CPU contention on shared/small VPS
- Background LSP scanning may be redundant with external editor LSP
Source: Hmbown/CodeWhale