CPU, round two: cheaper client captures, content-only redraws, damage-limited KMS and nested output
CI / test (push) Failing after 19s
CI / test (push) Failing after 19s
Measured on the MoonBit host, 1080p, cloud container (two runs each, before -> after): - full-screen (tiled) client redrawing at 60 fps: 43/39% -> 31/35% - 800x600 floating client at 60 fps: 15.5/13.2% -> 10.4/11.9% - client inside the nested window: nested 18% -> 12%, outer 17% -> 11.6% - Alt+Tab open over two animating clients: 36.6% -> 25.4% - idle (headless / nested): 0.2-0.6% -> 0.1-0.3% wasmhost raster: - capture keeps client pools mapped (keyed by dev/inode/size, dropped after 1 s unused) and reuses released surface buffers, swizzling a word at a time: 3.2 -> 2.1 ms per 1080p commit. - a window whose only change is a new buffer damages just its client area, and the topmost opaque buffer that covers the damage is drawn first (no backdrop copy, desktop card, lower windows or its own decoration under it): submit 3.2 -> 0.8 ms per full-screen frame. - the framebuffer tracks what changed since each output took it. The nested window's frames are a ring of three mapped memfds, each updated only where the screen changed, instead of a new memfd with a full 8 MB conversion and write every frame. - KMS: present copies only the rows the back buffer is missing (this frame's change and the last one's), and kms_stub.c is compiled with -O2 (its stub-cc-flags dropped moon's default, so the per-frame copy ran unoptimised). - images re-filled under the same handle (Alt+Tab previews) damage where the panel draws them: before, a live preview only repainted where it overlapped the window that redrew. compositor: - Alt+Tab previews of a window that keeps redrawing are remade at most every 100 ms (scaling a 1080p buffer takes ~2 ms); the loop keeps its pace while one is pending. - set-tokens is sent to the host only when the theme changes (it was 9 calls a frame). - /proc is sampled only when a module imports `system`; a machine without a battery looks for one every 30 s instead of probing eight sysfs paths every second. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hkh3qygSXtftCTVhSZ
This commit is contained in:
11 files changed
+455
-61
No files matched your search
+92
-5
@@ -153,6 +153,31 @@ extern "C" fn rs_thumbnail(id : UInt, w : Int, h : Int, reuse : Int) -> Int = "r
|
||||
///|
|
||||
extern "C" fn rs_blit_surface(id : UInt, x : Int, y : Int, w : Int, h : Int) -> Int = "rs_blit_surface"
|
||||
|
||||
///|
|
||||
extern "C" fn rs_surface_covers(id : UInt, w : Int, h : Int) -> Int = "rs_surface_covers"
|
||||
|
||||
///|
|
||||
extern "C" fn rs_maps_gc() = "rs_maps_gc"
|
||||
|
||||
///|
|
||||
extern "C" fn rs_image_take_changed(handle : Int) -> Int = "rs_image_take_changed"
|
||||
|
||||
///| Where the panel layer draws an image whose pixels changed under the same handle (the
|
||||
/// Alt+Tab switcher's live previews): the ops alone compare equal, so this is damage too.
|
||||
fn changed_images(panel : @wt.Val) -> R {
|
||||
let mut d : R = { x: 0, y: 0, w: 0, h: 0 }
|
||||
for op in panel.to_list() {
|
||||
if op is Variant("draw-image", Some(p)) &&
|
||||
rs_image_take_changed(p.field("image").to_int()) != 0 {
|
||||
d = union(d, rect_of(p.field("area")))
|
||||
}
|
||||
}
|
||||
d
|
||||
}
|
||||
|
||||
///|
|
||||
extern "C" fn rs_damage(x : Int, y : Int, w : Int, h : Int) = "rs_damage"
|
||||
|
||||
///|
|
||||
extern "C" fn rs_save_backdrop() = "rs_save_backdrop"
|
||||
|
||||
@@ -524,6 +549,43 @@ fn window_footprint(win : @wt.Val) -> R {
|
||||
}
|
||||
}
|
||||
|
||||
///| True when window `b` is window `a` with only a new client buffer (a client redrawing): same
|
||||
/// place, size and decoration.
|
||||
fn only_contents_changed(a : @wt.Val, b : @wt.Val) -> Bool {
|
||||
a.field("geometry") == b.field("geometry") &&
|
||||
a.field("fullscreen") == b.field("fullscreen") &&
|
||||
a.field("inset-top") == b.field("inset-top") &&
|
||||
a.field("inset-right") == b.field("inset-right") &&
|
||||
a.field("inset-bottom") == b.field("inset-bottom") &&
|
||||
a.field("inset-left") == b.field("inset-left") &&
|
||||
a.field("deco") == b.field("deco")
|
||||
}
|
||||
|
||||
///| True when `inner` lies inside `outer`.
|
||||
fn contains(outer : R, inner : R) -> Bool {
|
||||
inner.x >= outer.x &&
|
||||
inner.y >= outer.y &&
|
||||
inner.x + inner.w <= outer.x + outer.w &&
|
||||
inner.y + inner.h <= outer.y + outer.h
|
||||
}
|
||||
|
||||
///| The index of the topmost window whose opaque client buffer covers all of `area`: nothing
|
||||
/// under it (backdrop, desktop card, lower windows, its own decoration) shows there, so none of
|
||||
/// that is drawn. -1 when no window covers it.
|
||||
fn occluder(windows : Array[@wt.Val], area : R) -> Int {
|
||||
let mut i = windows.length() - 1
|
||||
while i >= 0 {
|
||||
let win = windows[i]
|
||||
let g = rect_of(win.field("geometry"))
|
||||
if contains(g, area) &&
|
||||
rs_surface_covers(win.field("surface").to_uint(), g.w, g.h) != 0 {
|
||||
return i
|
||||
}
|
||||
i = i - 1
|
||||
}
|
||||
-1
|
||||
}
|
||||
|
||||
///| The part of the screen `f` changes over `prev`, as one rectangle; None when all of it must
|
||||
/// be redrawn. Only window changes are narrowed down: any change to the wallpaper, desktop card,
|
||||
/// panel or the set of windows redraws everything.
|
||||
@@ -545,8 +607,14 @@ fn damage(prev : Frame, f : Frame) -> R? {
|
||||
if a == b {
|
||||
continue
|
||||
}
|
||||
if only_contents_changed(a, b) {
|
||||
// A new buffer in the same place: only the client area is drawn again.
|
||||
d = union(d, rect_of(b.field("geometry")))
|
||||
continue
|
||||
}
|
||||
d = union(d, union(window_footprint(a), window_footprint(b)))
|
||||
}
|
||||
d = union(d, changed_images(f.panel))
|
||||
if prev.popups != f.popups {
|
||||
for p in prev.popups.to_list() {
|
||||
d = union(d, rect_of(p.field("area")))
|
||||
@@ -623,9 +691,25 @@ fn submit(v : @wt.Val) -> Unit {
|
||||
Some(k) => k.w * k.h
|
||||
None => w * h
|
||||
}
|
||||
rs_maps_gc()
|
||||
match clip {
|
||||
Some(k) => rs_damage(k.x, k.y, k.w, k.h)
|
||||
None => rs_damage(0, 0, w, h)
|
||||
}
|
||||
// A full-screen (or tiled) client redrawing covers the whole damaged area with its own opaque
|
||||
// pixels: start from that window instead of from the backdrop.
|
||||
// (Only with the backdrop cached: a new wallpaper must still be drawn once to be kept.)
|
||||
let top = if backdrop_ready {
|
||||
occluder(f.windows, clip.unwrap_or({ x: 0, y: 0, w, h }))
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
let occluded = top >= 0
|
||||
let first = if occluded { top } else { 0 }
|
||||
|
||||
// 1. Wallpaper: drawn once, copied back while unchanged (only the damaged part).
|
||||
match f.wallpaper {
|
||||
Some(_) if occluded => ()
|
||||
Some(ops) =>
|
||||
if backdrop_ready {
|
||||
set_clip(clip)
|
||||
@@ -636,15 +720,18 @@ fn submit(v : @wt.Val) -> Unit {
|
||||
backdrop_ops.val = Some(ops)
|
||||
}
|
||||
None =>
|
||||
if rs_has_backdrop() != 0 {
|
||||
if rs_has_backdrop() != 0 && !occluded {
|
||||
set_clip(clip)
|
||||
rs_copy_backdrop()
|
||||
}
|
||||
}
|
||||
draw_ops(f.background.to_list(), 0, 0, clip)
|
||||
if !occluded {
|
||||
draw_ops(f.background.to_list(), 0, 0, clip)
|
||||
}
|
||||
|
||||
// 2. Windows, bottom to top.
|
||||
for win in f.windows {
|
||||
// 2. Windows, bottom to top (from the one covering the damage, when one does).
|
||||
for wi = first; wi < f.windows.length(); wi = wi + 1 {
|
||||
let win = f.windows[wi]
|
||||
let g = rect_of(win.field("geometry"))
|
||||
if clip is Some(_) {
|
||||
match intersect(Some(window_footprint(win)), clip) {
|
||||
@@ -652,7 +739,7 @@ fn submit(v : @wt.Val) -> Unit {
|
||||
_ => continue
|
||||
}
|
||||
}
|
||||
if !win.field("fullscreen").to_bool() {
|
||||
if !win.field("fullscreen").to_bool() && !(occluded && wi == first) {
|
||||
let it = win.field("inset-top").to_int()
|
||||
let ir = win.field("inset-right").to_int()
|
||||
let ib = win.field("inset-bottom").to_int()
|
||||
|
||||
Reference in new issue
Block a user