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
@@ -148,6 +148,18 @@ pub(all) struct SwitcherThumb {
|
||||
mut w : Int
|
||||
mut h : Int
|
||||
mut stale : Bool
|
||||
/// When it was last made (monotonic ms).
|
||||
mut made_ms : UInt64
|
||||
}
|
||||
|
||||
///| How often a preview of a window that keeps redrawing (a video) is made again: scaling a
|
||||
/// full-screen buffer down takes a couple of ms, too much for every frame of every window.
|
||||
const THUMB_REFRESH_MS : UInt64 = 100UL
|
||||
|
||||
///| True while the switcher is up and a preview waits for its next refresh (the main loop
|
||||
/// keeps its frame pace for it).
|
||||
fn ChandraCompositor::thumbs_pending(self : ChandraCompositor) -> Bool {
|
||||
self.switcher_on && self.thumbs.values().any(t => t.stale)
|
||||
}
|
||||
|
||||
///| The window committed a new buffer: its preview is made again the next time it is shown.
|
||||
@@ -204,8 +216,10 @@ fn ChandraCompositor::switcher_thumb(self : ChandraCompositor, id : UInt64, box_
|
||||
}
|
||||
Some(buf) => {
|
||||
let (tw, th) = thumb_fit(buf.width, buf.height, box_w, box_h)
|
||||
let now = @sys.monotonic_ms()
|
||||
match old {
|
||||
Some(t) if !t.stale && t.w == tw && t.h == th => return (t.handle, tw, th)
|
||||
Some(t) if t.w == tw && t.h == th && t.handle != 0U &&
|
||||
(!t.stale || now - t.made_ms < THUMB_REFRESH_MS) => return (t.handle, tw, th)
|
||||
_ => ()
|
||||
}
|
||||
let reuse = match old {
|
||||
@@ -240,8 +254,12 @@ fn ChandraCompositor::switcher_thumb(self : ChandraCompositor, id : UInt64, box_
|
||||
t.w = tw
|
||||
t.h = th
|
||||
t.stale = false
|
||||
t.made_ms = now
|
||||
// New pixels under the same handle: the frame must be drawn even when nothing else
|
||||
// changed (the host finds where the preview is).
|
||||
self.damage.mark_rect(@scene.Rect::new(0, 0, tw, th))
|
||||
}
|
||||
None => self.thumbs.set(id, { handle: h, w: tw, h: th, stale: false })
|
||||
None => self.thumbs.set(id, { handle: h, w: tw, h: th, stale: false, made_ms: now })
|
||||
}
|
||||
(h, tw, th)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user