Repository navigation
base: read the pointer only under hovered text, and ask no frame for a closed popup - #3431
Merged
Merged
Conversation
…a closed popup Two things that kept a long list of rendered markdown, as an AI chat transcript is, from being drawn from last frame under gpui-fast's retained views: - Inline text read the pointer's position on every paint to find the link under it, which made every paragraph depend on every pointer move: a scrollbar drag or any mouse move drew the whole transcript again. It now reads the pointer only when its own hitbox is hovered; text not under the pointer has no link under it. - A popup asked for an animation frame the first time it measured its trigger, so that its content could be placed on the next frame. A closed popup has no content to place, and every row coming into view with one asked for a frame, which keeps a list off its scroll layer. It now asks only when it has content; opened later, it places the content at once from the bounds it already noted.
sunli829
marked this pull request as ready for review
October 12, 2026 02:36
a_closed_popup_asks_for_no_frame_and_opens_at_once did not compile: it called cx.run_until_parked() while the window it had added still borrowed cx. Compiled, it still could not tell the change apart: it counted the root view's renders, and upstream GPUI renders the root view on every draw, so the count was three with or without the popup asking for a frame. It now asks the window how many next-frame callbacks the first draw left (Window::simulate_next_frame): none for a closed popup, one if it still asks for a frame.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Allsum users reported high CPU when dragging the scrollbar of a longer AI chat conversation. Under gpui-fast's retained views, whatever did not change since the last frame is drawn from it; two things in
gpui-basekept a long list of rendered markdown from ever being unchanged. Both changes are ingpui-base(AGENTS.md asks for an explicit request before changing Base; this was requested as part of the Allsum investigation).Changes
text/inline.rs: read the pointer only under hovered text.Inline::paintreadwindow.mouse_position()on every paint to find the link under the pointer. Reading the pointer makes the text depend on every pointer move, so a scrollbar drag, or any mouse move, drew every paragraph of the transcript again. It now reads the pointer only when its own hitbox is hovered; text not under the pointer has no link under it, so the result is the same.popup.rs: a closed popup asks for no frame. APopupasked for an animation frame the first time it measured its trigger, so that its content could be placed on the next frame. A closed popup has no content to place, yet every list row coming into view with one asked for a frame, and a list whose rows ask for frames is kept off its scroll layer. It now asks only when it has content; opened later, it places its content at once from the trigger bounds it already noted.Measurements
In Allsum, with the gpui-fast fixes (longbridge/gpui-fast#56) and longbridge/ai-chat#438: turning off the inline-text change raised scrollbar-drag CPU from ~19 % to ~38 %; turning off the popup change raised it to ~27.5 %. With everything, wheel 47 % → 22 % and drag 32 % → 20 % against main.
Tests
a_closed_popup_asks_for_no_frame_and_opens_at_once(a closed popup renders its view once; opened, its content is placed on that frame).quickjsgit dependency, whose fetch is still in progress here. The changed code compiles (built into Allsum on top of 02daace). I will update this once the tests have run.🤖 Generated with Claude Code