Files
zed/crates/markdown
Parker Loflin c016f436e6 markdown: Skip the window-wide refresh after parsing once the element is painted (#67255)
## Summary

When a background parse finishes, `Markdown` calls `cx.notify()` and
then `cx.refresh_windows()`. The refresh makes the next frame of every
window bypass `.cached()` views, so every pane and dock panel in every
window re-renders. While the agent streams a response,
`Markdown::append` reparses on each 16 ms reveal tick, so nearly every
frame rebuilds the whole workspace. The markdown preview does the same
after each reparse.

The refresh came in #31486, when `MarkdownElement` didn't register its
entity as a view, so `cx.notify()` alone didn't redraw it. #31585 fixed
that a day later with `window.set_view_id` in prepaint. `Markdown` now
refreshes windows only when a window's last frame read it without
drawing it as a view: consumers that hide the element while parsing, or
that only measure it. The new `App::is_read_without_view` checks this
against the rendered frame. Otherwise `cx.notify()` redraws the element
and its ancestors. Markdown that no window read in its last frame no
longer triggers a refresh.

In a GPUI test window with a painted `MarkdownElement` and a cached
sibling view, each finished parse re-rendered the sibling. It no longer
does. I didn't time this in a full workspace.

## Testing

- `test_parsing_painted_markdown_does_not_redraw_cached_siblings` is
new. It appends to a painted `Markdown` next to a cached sibling view,
then checks that the new text renders and the sibling doesn't re-render.
It fails without the change.
- `test_parsing_redraws_markdown_shown_only_once_parsed` is new. A
cached view hides the element while parsing, and the test checks that
the text renders after the first parse and after a later reparse. It
fails if the refresh is removed outright.
- `cargo test -p gpui -p markdown -p markdown_preview -p agent_ui -p
editor -p git_ui` passes.
- `./script/clippy -p gpui -p markdown` passes.
- In a Zed dev build, agent text streams from a mock model and the blame
popover renders after its first parse.
- The video covers a reparse that hides the element. No shipped view
does this, so both builds use a temporary patch that hides the markdown
preview while parsing and drops its post-parse search event. Over 3 runs
each, the previous version of this PR left the preview blank for about 1
s after the parse finished. With this version, the text returned within
22 ms.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Improved rendering performance while agent responses stream in
- [GPUI] Added `App::is_read_without_view` to check whether notifying an
entity redraws the views that read it



https://github.com/user-attachments/assets/76be4568-c9cf-49bd-9633-b3f8b46d8058
2026-11-24 19:41:38 +00:00
..