Idle desktop sleeps instead of redrawing; only changed parts of the screen are redrawn
CI / test (push) Failing after 15s
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:
19 files changed
+542
-68
No files matched your search
@@ -19,11 +19,14 @@ fn wasmImportUnlink(p0 : Int, p1 : Int) = "chandra:host/sys@0.1.0" "unlink"
|
||||
fn wasmImportPollRead(p0 : Int, p1 : Int) -> Int = "chandra:host/sys@0.1.0" "poll-read"
|
||||
|
||||
///|
|
||||
fn wasmImportTakeFd(p0 : Int) -> Int = "chandra:host/sys@0.1.0" "take-fd"
|
||||
fn wasmImportWaitReadable(p0 : Int, p1 : Int, p2 : Int) -> Int = "chandra:host/sys@0.1.0" "wait-readable"
|
||||
|
||||
///|
|
||||
fn wasmImportRecvmsg(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/sys@0.1.0" "recvmsg"
|
||||
|
||||
///|
|
||||
fn wasmImportTakeFd(p0 : Int) -> Int = "chandra:host/sys@0.1.0" "take-fd"
|
||||
|
||||
///|
|
||||
fn wasmImportSendmsg(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "chandra:host/sys@0.1.0" "sendmsg"
|
||||
|
||||
@@ -78,6 +81,17 @@ fn wasmImportHasExe(p0 : Int, p1 : Int) -> Int = "chandra:host/sys@0.1.0" "has-e
|
||||
///|
|
||||
fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "chandra:host/sys@0.1.0" "spawn"
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array8
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
@@ -94,13 +108,6 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array8
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
@@ -108,12 +115,13 @@ extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#| local.get 1 call $moonbit.init_array16
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
#owned(array)
|
||||
extern "wasm" fn mbt_ffi_int_array2ptr(array : FixedArray[Int]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
@@ -25,21 +25,26 @@ fn wasmImportUnlink(p0 : Int, p1 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportTakeFd(p0 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPollRead(p0 : Int, p1 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportWaitReadable(p0 : Int, p1 : Int, p2 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportRecvmsg(p0 : Int, p1 : Int, p2 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportTakeFd(p0 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSendmsg(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
@@ -130,6 +135,16 @@ fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_str2ptr(str : String) -> Int {
|
||||
abort("wasm-only")
|
||||
@@ -145,22 +160,17 @@ fn mbt_ffi_malloc(size : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_int_array2ptr(array : FixedArray[Int]) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
@@ -57,6 +57,20 @@ pub fn poll_read(fd : Int, timeout_ms : Int) -> Int {
|
||||
let ret = result
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// Block until one of `fds` is readable or `timeout-ms` passes: how an idle compositor sleeps.
|
||||
/// While the login-session display is open (display.open) its own seat, DRM and input fds are
|
||||
/// waited on too. The number of ready fds, 0 on timeout, <0 on error.
|
||||
pub fn wait_readable(fds : FixedArray[Int], timeout_ms : Int) -> Int {
|
||||
|
||||
let ptr = mbt_ffi_int_array2ptr(fds)
|
||||
|
||||
let result : Int = wasmImportWaitReadable(ptr, fds.length(), timeout_ms);
|
||||
let ret = result
|
||||
mbt_ffi_free(ptr)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn recvmsg(fd : Int, max_len : UInt) -> Received {
|
||||
|
||||
Reference in new issue
Block a user