Skip to content

Rest: free the kept last frame after 60 s idle with one shared 60 s timer; refill on an idle turn - #1063

Closed
Hona wants to merge 4 commits into
devfrom
memory-rest-kept-frame-dev
Closed

Hona wants to merge 4 commits into
devfrom
memory-rest-kept-frame-dev

Conversation

@Hona

@Hona Hona commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Replaces the 10 s kept-frame drop with PRESENT's option (a) and the single 60 s window::rest deadline (LONG_REST_AFTER, shared with swap-chain depth when unseen).

What changes

  • Visible 60 s rest (GiveBackKept): after 60 s with no drawn frame (LONG_REST_AFTER), window::rest drops render::damaged's full-window Retained texture (~9.2 MB at 1920x1200) and calls device.poll(PollType::Poll) once without waiting, so wgpu frees the texture without waiting for a frame.
  • First frame back: an armed frame while Retained is away draws whole straight into the drawable (whole: "given back"), allocating and copying nothing on the input frame.
  • Off-frame refill (post_frame_turn): on Windows, the next idle turn with no input waiting re-creates Retained and draws the current frame whole into it with no present, so the following armed frame finds it current.
  • Single 60 s timer (Rest::Unseen + keeps_third_buffer): going out of sight (RestEvent::Unseen: hidden, minimised, covered whole) drops Retained immediately in GiveBackAll and holds Rest::Unseen { long: now + LONG_REST_AFTER } (keeps_third_buffer() == true), emitting RestEffect::DropThirdBuffer at 60 s so swap-chain depth shares the same timer. Non-Windows targets arm no 60 s wake.

Gate results (3 runs, blade Iris, release-quick + frame-profile, exclusive timing tickets)

proof/memory/runs/longrest-kept-{1,2,3} (longrest-kept-{1,2,3}-frames.jsonl):

Metric Run 1 Run 2 Run 3 Median
GPU memory at rest8 → rest63 (no frame drawn) 52,572,160 → 39,362,560 B 52,785,152 → 39,571,456 B 52,633,600 → 39,424,000 B −13,209,600 B
First frame encode after ~10.5 s rest (partial) 0.063 ms 0.059 ms 0.070 ms 0.063 ms
First frame encode after 65.3 s rest (given back) 0.065 ms 0.068 ms 0.066 ms 0.066 ms (+3 µs)
First frame total after 65.3 s rest (given back) 4.029 ms 3.740 ms 1.951 ms 3.740 ms (3/3 < 4.167 ms)
First frame total after 53.7 s rest (kept frame held) 5.928 ms 2.793 ms 5.005 ms 5.005 ms

Tests

  • Mac whole suite (06aee70f): 3,088 passed, 1 failed (the known order-dependent runtime::tests::scroll_children::scroll_xy_with_direct_children_scrolls_both_axes_and_warns_on_trailing_growth_sibling); clipboard::macos included, general pasteboard 17 → 17 (proof/memory/mac-pr1063-06aee70f-all.log).
  • Windows and wasm: cargo check passes; whole Windows suite queued in PROOF-FARM's lane (06aee70f). Zero test files added or edited.

Partial frames (#852) redraw changed rectangles into a window-sized texture the renderer keeps, and copy it to the drawable. The first partial frame makes it and nothing gave it back: after a session is open and closed, Home holds it for the window's life (9,708,544 B of GPU memory at 1920x1200 on an Iris Xe, mapped into the process as private bytes). Rest now drops it with the other textures it gives back; the next partial frame finds no kept frame and draws whole into a new one, as the first one does.
Copilot AI balanced review requested due to automatic review settings November 16, 2026 07:30

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. Try requesting a review at a lower effort level.

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

Hona commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Not merging as is. Two findings on blade (Iris, diagnostic and frame-profile builds of app 11186af0 with this change on Rune 631e8a67):

  • It frees nothing at an idle rest. Back on Home, wgpu still holds 6 textures / 11,052,036 B, the same as without the change. Rune drops its handle, but wgpu frees a texture the last submission used only at the next device poll, and an idle rest doesn't poll (window/rest.rs). The bytes would come back at the next frame, which is when they're wanted again.
  • The first frame after a rest costs more than a partial frame. That frame re-creates the texture and draws whole into it. Encode is 0.064-0.071 ms without the change against 0.889-0.894 ms with it. Total is 1.09-1.16 ms against 1.99-2.16 ms for a wheel notch, and 1.27-1.31 ms against 2.28-2.65 ms for a tap on search. Two runs per side.

Proposal, for PRESENT: free it only after a longer idle period, with a non-blocking poll so the bytes actually go, and re-create it off the input frame. Converting to draft.

@Hona
Hona marked this pull request as draft November 16, 2026 09:44
Hona added 3 commits November 17, 2026 20:05
…imer; refill on an idle turn

Replaces the 10 s rest drop with PRESENT's option (a) and the shared 60 s `Rest` deadline (`LONG_REST_AFTER`):
- Visible and idle for 60 s: `GiveBackKept` drops `Retained` and calls `device.poll(PollType::Poll)` once so wgpu frees the ~9.2 MB texture without a frame.
- Out of sight (`RestEvent::Unseen`): `GiveBackAll` drops `Retained` immediately and `Rest::Unseen { long }` holds the single 60 s deadline (`keeps_third_buffer`) before emitting `DropThirdBuffer`.
- First frame back: draws whole straight into the drawable (`whole`: "given back"), making and copying nothing on the input frame.
- Next idle turn with no input waiting (`post_frame_turn`): re-creates `Retained` and draws the current frame whole into it with no present.
@Hona Hona changed the title Windows: a window at rest gives back its kept last frame Rest: free the kept last frame after 60 s idle with one shared 60 s timer; refill on an idle turn Nov 17, 2026
@Hona
Hona marked this pull request as ready for review November 17, 2026 12:05
@Hona

Hona commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Closing (owner's decision): the measured build freed nothing at an idle rest and made the first frame after it slower; the current head was not measured again, and it conflicts in 5 places with dev. Branch kept.

@Hona Hona closed this Nov 21, 2026
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