-
-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
The heartbeat timer calls agent-shell--update-header-and-mode-line on every tick (10/sec by default), which in turn calls agent-shell--make-header-model. This function uses seq-find to look up the model name from the models list:
(model-name (or (map-elt (seq-find (lambda (model)
(string= (map-elt model :model-id)
(map-nested-elt state '(:session :model-id))))
(map-nested-elt state '(:session :models)))
:name)
...))EDIT: The above seq-find analysis is speculation by Claude, not from profiler data. See comments for actual profiler output.
With many agent-shell buffers open (e.g., 32), this results in significant CPU usage since the lookup runs 320 times per second across all buffers.
Proposed fix
Skip the header update in the heartbeat callback when agent-shell-show-busy-indicator is nil, since there's no animation to update:
:on-heartbeat
(lambda (_heartbeat _status)
(when agent-shell-show-busy-indicator
(when (get-buffer-window shell-buffer)
(with-current-buffer shell-buffer
(agent-shell--update-header-and-mode-line)))
...))This allows users who don't need the busy animation to avoid the overhead entirely.
Alternative approaches
- Cache the model-name lookup (invalidate when model changes)
- Only update when status actually changes (started → busy → ended), not on every tick
- Use a hash table for model lookup instead of seq-find
Written by Claude
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working