Repository navigation
Conversation
agent-shell-prompt-ranges walked every font-lock-face change in the buffer, and chat mode calls it on every shell event. On long sessions this dominated streaming: a 1.6 MB buffer (10 turns, mostly collapsed tool output) took ~0.2s per relabel. Cache the prompt runs before the next-to-last one and rescan only from there, since a busy shell streams between the submitted prompt and the live one. An after-change-functions hook drops the cache on any change at or before that run (clear, session reload). Narrowed calls scan without touching the cache.
77d4fe3 to
c125764
Compare
agent-shell-prompt-ranges stopped at every font-lock-face change, which grows with the session and slowed chat mode relabeling on long buffers. Prompts end where comint's output field gives way to input, as comint-next-prompt relies on, so walk field instead for faster results.
|
Thanks for the profiling and the PR! Before caching, I'd like to see if we can make the scan itself cheap: a cache depends on every earlier change running modification hooks, which nothing enforces. I've pushed a change that walks |
|
Tried 78a2c94: same ranges as the old scan, and the stuttering is gone. Per relabel:
Agreed the cache isn't worth its fragility, closing this. FWIW the cost still grows with the buffer, ~14 ms per MB on my DeepSeek sessions: |
|
Thank you for retesting and profiling.
Increasing |
agent-shell-prompt-rangeswalked everyfont-lock-facechange in the buffer, and chat mode calls it on every shell event, so relabel cost grew with the whole session.I noticed Emacs stuttering while a fast agent was streaming into a long session. Over 40s of streaming, the profiler put 71% of CPU in
agent-shell-chat--relabel-buffer→ the prompt scan. That buffer was 1.6 MB: 10 turns, ~97% collapsed tool output, ~29k face runs. Each relabel took 0.17–0.27s.Cache the prompt runs before the next-to-last one and rescan only from there, since a busy shell streams between the submitted prompt and the live one. An
after-change-functionshook drops the cache on any change at or before that run (clear, session reload). If the cached position no longer holds a prompt face, it falls back to a full scan. A narrowed buffer is scanned in full and leaves the cache alone.Same buffer (1.7 MB by now):
agent-shell-prompt-rangesagent-shell-chat--relabelOver ~2800 calls in normal use, including turn boundaries, the cached result matched a full scan every time I compared them.
Not addressed:
agent-shell-prompt-rangesstill checks each run for the end-of-prompt marker (~1 ms here).font-lock-facein agent-shell or shell-maker.Checklist
M-x checkdocandM-x byte-compile-file.