Skip to content

Skip setting overlays on collapsed fragments#585

Open
AdamNiederer wants to merge 2 commits into
xenodium:mainfrom
AdamNiederer:partially-fix-fragment-perf
Open

Skip setting overlays on collapsed fragments#585
AdamNiederer wants to merge 2 commits into
xenodium:mainfrom
AdamNiederer:partially-fix-fragment-perf

Conversation

@AdamNiederer
Copy link
Copy Markdown

@AdamNiederer AdamNiederer commented May 18, 2026

Partial resolution of #584

Before:

1,868,011,162  93% + timer-event-handler

         8541  48% + timer-event-handler
         6263  35%   Automatic GC
         2373  13% + redisplay_internal (C function)

After:

 979,703,965  88% + timer-event-handler

        7261  39% + redisplay_internal (C function)
        5444  29% + timer-event-handler
        5411  29%   Automatic GC

redisplay is no longer throttled and we save ~1GB of garbage on a 32k fragment length. CPU usage is still high but it's no longer causing major UI stutter. Expanded fragments still need help and there's probably some more optimization that could be done for both cases.

Checklist

  • I agree to communicate (PR description and comments) with the author myself (not AI-generated).
  • I've reviewed all code in PR myself and will vouch for its quality.
  • I've read and followed the Contributing guidelines.
  • N/A I've filed a feature request/discussion for a new feature.
  • N/A I'm making visual changes, so I'm including screenshots so you can view and discuss.
  • N/A I've added tests where applicable.
  • I've updated documentation where necessary.
  • I've run M-x checkdoc and M-x byte-compile-file.

@AdamNiederer AdamNiederer force-pushed the partially-fix-fragment-perf branch from e215c2c to 44ff21e Compare May 18, 2026 05:03
Comment thread agent-shell-ui.el
(map-put! state :collapsed new-collapsed-state)
(put-text-property (map-elt block :start)
(map-elt block :end) 'agent-shell-ui-state state)))))
(map-elt block :end) 'agent-shell-ui-state state)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agent-shell-ui.el is fairly generic in enabling buffer updates through collapsable fragements. With this change, we'd be introducing client-specific logic.

I'd prefer if we found a way to keep markdown-specific logic in agent-shell.el. Maybe through an agent-shell-ui-post-toggle-fragment-at-point-function (hook) that we funcall from here? Happy to consider alternatives.

@xenodium
Copy link
Copy Markdown
Owner

Thanks a lot for the PR! Source block highlighting in markdown-overlays.el is highly inneficient. I'm working on a separate markdown rendering solution but that will take a little more time. I'll push it to a branch somewhat soon.

WRT to the PR itself, I'm happy to merge for the time being but could we please address the comment in review? Alternatively, isn't agent-shell-highlight-blocks set to nil enough to improve the immediate issue?

@AdamNiederer AdamNiederer force-pushed the partially-fix-fragment-perf branch from c4a2fe4 to 44ff21e Compare May 19, 2026 01:42
@xenodium
Copy link
Copy Markdown
Owner

Thank you for the follow-up changes. Could you resolve the conflicts so they can merged?

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.

2 participants