Skip to content

Windows: a frame only a loop asked for runs the loop alone - #1136

Merged
Hona merged 29 commits into
devfrom
motion/loop-only-frame
Nov 18, 2026
Merged

Hona merged 29 commits into
devfrom
motion/loop-only-frame

Conversation

@Hona

@Hona Hona commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

While a turn runs, the Working shine asks for a frame every refresh. Each of those frames used to run the app's poll, rebuild the view, lay it out, walk every node in paint, and compare every instance with the last frame's, all to move 7 glyph clips. Now a frame that only a loop asked for runs the loop and nothing else.

CPU per shine frame (blade, Windows, Iris Xe, 800x540 at 1.5x, 240 Hz, frame-profile builds, medians in µs)

One frame Before After
The Working shine (6.4 instances written per frame after) 710–1,204 316–357
Build (view, layout, paint) 282–562 1–9
Encode 62–102 18–46
A running tab's spinner (24 dots, 60 frames/s) 811–1,115 446–565
Floor: a window whose only content is an invisible loop 293–402

That runs 240 times a second for the whole of every reply.

flowchart LR
  F["frame only a loop asked for"] --> C{"nothing reached the window;<br/>every loop on screen is a slot or a window;<br/>nothing would show or hide;<br/>same swap chain as the last frame"}
  C -- no --> O["ordinary frame"]
  C -- yes --> S["loop_step: sample the loops into<br/>the instances they drew"]
  S --> U["upload only those instances"]
  U --> D["redraw, where an instance differs from the buffer,<br/>its old and new pixels, with only the instances that reach them"]
  D --> P["present those rectangles"]
Loading
  • Two kinds of loop qualify:
    • A spinner's dot: an opacity cycle on a plain fill. The web already had this path; now the dot's ancestors' opacity can be under 1, as in a tab's ring.
    • A window sliding sideways over content that slides back inside it: clip_fade on a LoopSpec::slide whose only child slides the other way, as session-view's shimmer is made. The content holds still, so a step moves only the window's clip and soft edges (runtime/paint/slide.rs).
  • One anchor for the window's clip, in paint and in the step. An ordinary frame poses the window from the scene's layout origin plus the offset, then adds its ancestors' translation (Scene::frame's origin_dual, then build's rect_pt). A step would add the offset's change to the last paint's rect. The two float sums land one 1/64-pixel grid step apart where the offset sits on a grid line's half. Drawn side by side, that was a 1/255 change in 35 of 612 steps at 1.5x. So both pose the window through pose_rect from one Anchor: a rect at an offset, kept across paints while the window's laid-out place holds (slide_anchor). The check needs no tolerance. Across the slide, the window snaps as a still box does, and its clip takes those whole-pixel top and bottom.
  • What takes an ordinary frame instead:
    • any event since the last frame (window/loop_frame.rs);
    • a due timer or poll deadline, a commit, input, or any other motion;
    • a loop that paint couldn't record, or a slide up or down: text paints only the lines near its clip, so a vertical window could uncover lines never drawn;
    • a step that would show or hide a node or a glyph (about 3% of the shine's frames, as glyphs enter and leave the band).
  • A new swap chain draws its first frame whole. Every successful surface configure gets a number (window/configure.rs); Damage keeps the number it drew on, and a frame on a different one plans whole, loop-only or not. That covers rebind_alpha, a replaced surface, a resize, a blend switch, and acquire reconfiguring an outdated surface inside a frame.
  • No frame is loop-only while an app wake is on its way. The app's waker sets a per-window flag before it posts its event. The event clears the flag before drain polls, so a streamed token, a tool's result or a toast that another thread queued is polled at once, as on dev.
  • A missed frame can't leave a dot stale. Every step writes every dot. arm_loop then redraws only the instances whose bytes differ from what the instance buffer holds: a dot a missed frame stepped is redrawn, and a stepped spinner's dots between steps are not.
  • The glide, Windows only: a stepped window's own edges, and its content's, land between pixels instead of snapping, so a step and an ordinary frame draw the same picture. That's decided by shape, at compile time on Windows (slide_glides): every other slide, and every slide on macOS, Linux and the web, snaps as on dev (the kit's indeterminate progress bar included).
  • poll no longer runs on frames only a loop asked for. Work an app does on a timer asks with Tx::wake_after, as on a window at rest. The desktop app's polls that are live during a turn all do (rows below).
  • macOS, Linux and the web draw as on dev: they have no loop-only frames (the decision is Windows-only), and every slide snaps as before. The web keeps its own spinner step, which now also takes a dot under a faded ancestor. RUNE_LOOP_CHECK=1 works in a headless run on every platform (it checks loop_step, which is shared). RUNE_LOOP_CHECK=2 and the kept-frame pixel check exist only on Windows (and the web's build), where partial frames do; elsewhere they are absent.
  • Diagnostics:
    • frame-profile: the frame log says when a frame was loop-only (looped: the instances it wrote), why one wasn't (loop_why), and how many frames were missed since the last drawn one (missed); RUNE_MISS_LOOP_FRAMES=<n> makes every nth loop-only frame miss its drawable;
    • RUNE_LOOP_CHECK=1 runs every frame a step could draw as an ordinary frame and compares the instances; in a headless run (--frames, any platform) it asks before every frame and ends with a tally;
    • RUNE_LOOP_CHECK=2 (Windows) compares pixels: each loop-only frame's kept picture against the same instances drawn whole.

The step against the ordinary frame

Frame-profile builds at this head; every launch with OPENCODE_RUNE_OTEL=0.

Row Where Result
RUNE_LOOP_CHECK=1, the floor app headless: the shine, the shine beside a spinner, a list scrolling under the shine, a reply streaming 1x, 1.5x, 1.875x 340 / 340 / 89 / 271–274 steps checked at every scale, 0 differ (largest difference 0); exit 0
The same in a window: a spinner under a faded parent; the shine beside it 1.5x 430 and 1,606 steps checked, 0 differ
The desktop app in a window: a reply streaming, the Working shine, two running tabs' spinners, notched wheel glides over the timeline 1.5x 917 steps checked, 0 differ
RUNE_LOOP_CHECK=2, the same app scene (each loop-only frame's picture against the whole frame's) 1.5x 480 loop-only frames compared, 0 differing pixels
The same with RUNE_MISS_LOOP_FRAMES=7 (89 frames missed, a spinner on screen) 1.5x 0 differing pixels
Exit codes: clean; spoiled (RUNE_LOOP_CHECK_SPOIL), fast and orderly exit; a resize mid-run 0; 3, 3; alive after the resize, then 0 or 3
Refusals: a vertical slide; a spinner alone headless (a headless run repaints every frame, so a stepped cycle is never due there) 0 checked, exit 3, the reason named

Ordinary frames against dev 307b2cd7, headless, every 6th frame of 2 s, 40 pairs per row. Every difference lies inside the shine's band and is at most 3/255 (2/255 at 1.5x and 1.875x). It is the designed glide: on dev the band steps a whole pixel at a time. Screens with no sliding window are byte-identical.

Scene 1x 1.5x 1.875x
Floor: the shine 27 of 40 pairs differ, ≤ 3/255 32, ≤ 2/255 36, ≤ 2/255
Floor: a list scrolling under the shine 27, ≤ 3/255 31, ≤ 2/255 33, ≤ 2/255
App: the Working row 27, ≤ 3/255 32, ≤ 2/255 37, ≤ 2/255
App: a reply streaming 36, ≤ 3/255 36, ≤ 2/255 36, ≤ 2/255

GPU (blade, on screen, the same window size for each)

Official's shine on screen at a matched window size, and the GPU per shine frame before and after, are in one timing ticket on GPUI's list (blade's screen).

Hona added 9 commits November 17, 2026 14:48
When nothing reached the window since its last frame and every loop on screen is one a step can draw (a spinner's dots, or a sliding window over content that slides back inside it, as a text shimmer is made), the frame samples the loops into the instances they drew and skips poll, view, layout, paint and the instance diff. Only those instances upload, only the pixels they cover redraw (with only the instances that reach them), and only those present. A sliding loop's own edges glide between pixels; what it holds still snaps.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Hona added 19 commits November 18, 2026 08:07
…ndows a step can move (Windows), no slide up or down, unchanged dots not redrawn; RUNE_LOOP_CHECK in headless runs
…r (a missed frame's included); any surface configure makes the next frame whole; RUNE_LOOP_CHECK=2 compares pixels; RUNE_MISS_LOOP_FRAMES (frame-profile)
… differed, fails (exit 3); the pixel check compares its last frame too
…e 3, fast or orderly exit, never mid-run; RUNE_LOOP_CHECK_SPOIL (frame-profile) for its failing row
…he ordinary frame's is drawn beside it and the pictures compared; any differing pixel fails the run
…nchor, so their clips are the same numbers; the check has no tolerance again, and its ordinary frame samples at the step's clock
…n't handled, so work it brought is polled at once
…s it its edges land on whole pixels, as before
…p takes the snapped top and bottom and glides along the slide from its anchor
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