Idle desktop sleeps instead of redrawing; only changed parts of the screen are redrawn
CI / test (push) Failing after 15s

Measured headless and nested at 1080p (host-wasm), against main:
- Idle: ~9.4% CPU per compositor -> ~0.35%. Idle frames cost ~1.3 ms, and the loop
  woke 60-125 times a second to find nothing had changed.
- One 800x600 floating client animating at 60 fps: 33% -> 16% CPU; raster per frame
  ~4.5 ms -> ~0.9 ms. A full-screen tiled client: 65% -> 54% (its cost is now mostly
  copying the 8 MB buffer out of the client's shared memory).

Changes:
- shell: the wallpaper and desktop card ops (~1900, the moon disc is drawn per pixel)
  are kept and reused until what they are drawn from changes (size, theme, wallpaper,
  card position, date, hour:minute). This was ~75% of an idle frame.
- FrameSig compares the background by identity first instead of op by op.
- Host tables (windows, layouts, ...) are only sent to the host when their bytes change.
- Main loop: a pass with no input, no changed frame and nothing waiting to be shown
  blocks in the new sys.wait-readable on the Wayland socket and clients (plus the
  nested host connection; the login session's seat, DRM and libinput fds are added by
  the host) until just before the wall clock's next second, then polls every 5 ms
  until it turns, so clocks still tick on time. Recording, pending screenshots and
  toasts keep the frame pace (ChandraCompositor::has_timed_work).
- Host raster: works out what changed from the last frame. When only windows changed
  (a client drew, a window moved, focus moved) it redraws just their footprint
  (decoration and shadow included, old and new place), copying back only that part
  of the cached backdrop; anything else still redraws everything. A test checks the
  partial redraw is pixel-identical to a full one for a client redraw, a move and a
  focus change with stacking swapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hku78wdzXtY9QsR9NW
This commit is contained in:
Claude committed 2026-11-25 19:21:39 +00:00
1 parent 2d9f4e34c5
commit ba82d3c59b
19 files changed
+542 -68

No files matched your search

+56 -5
View File
@@ -223,6 +223,10 @@ pub(all) struct DesktopShell {
mut wallpaper_len : Int
/// Which wallpaper is drawn (an index into `@libshell.wallpaper_names`); the wallpaper module sets it.
mut wallpaper_sel : Int
/// The background ops (wallpaper + desktop card) and what they were built from: rebuilt only
/// when that changes (about once a minute), not every frame.
mut bg_cache : Array[@scene.DrawOp]
mut bg_key : BgKey?
/// Session settings (the session settings module flips them; saved in state.edn): reopen the
/// last session's windows at the next start, and remember where floating windows were left.
mut restore_session : Bool
@@ -326,6 +330,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
screen_w: 0,
wallpaper_len: 0,
wallpaper_sel: 0,
bg_cache: [],
bg_key: None,
restore_session: true,
screenshot_state: 2,
remember_windows: true,
@@ -800,6 +806,55 @@ pub fn DesktopShell::take_actions(self : DesktopShell) -> Array[ShellAction] {
out
}
///| What the background (wallpaper + desktop card) is drawn from.
#derive(Eq)
struct BgKey {
w : Int
h : Int
theme : @scene.ThemeTokens
wallpaper : Int
x : Int
y : Int
date : (UInt, Byte, Byte, Byte)
hour : Byte
minute : Byte
}
///| The wallpaper and the desktop card. Building them costs most of an idle frame (the card's
/// moon disc alone is ~1800 ops), so the last ops are kept, the same array, until something they
/// are drawn from changes: the card shows minutes, so that is about once a minute.
fn DesktopShell::background(
self : DesktopShell,
w : Int,
h : Int,
theme : @scene.ThemeTokens,
tokens : @theme.Tokens,
) -> Array[@scene.DrawOp] {
let at = now()
let (dx, dy) = self.desk_pos()
let key : BgKey = {
w,
h,
theme,
wallpaper: self.wallpaper_sel,
x: dx,
y: dy,
date: (at.year, at.month, at.day, at.weekday),
hour: at.hour,
minute: at.minute,
}
if self.bg_key == Some(key) {
return self.bg_cache
}
let bg : Array[@scene.DrawOp] = []
translate(@libshell.render_wallpaper(@ui.size(w, h), tokens, self.wallpaper_sel), 0, 0, bg)
self.wallpaper_len = bg.length()
render_desktop_widget(dx, dy, tokens, at, bg)
self.bg_cache = bg
self.bg_key = Some(key)
bg
}
///| Build the (background, panel) render-lists for the current frame.
pub fn DesktopShell::render(
self : DesktopShell,
@@ -823,11 +878,7 @@ pub fn DesktopShell::render(
if self.widgets.iter().any(w => w.has_cap("icons")) {
self.publish_icons()
}
let bg : Array[@scene.DrawOp] = []
translate(@libshell.render_wallpaper(@ui.size(w, h), tokens, self.wallpaper_sel), 0, 0, bg)
self.wallpaper_len = bg.length()
let (dx, dy) = self.desk_pos()
render_desktop_widget(dx, dy, tokens, now(), bg)
let bg = self.background(w, h, theme, tokens)
let panel_ops : Array[@scene.DrawOp] = []
self.comps.clear()