Stop redrawing an unchanged desktop; faster fills and blits; --profile
CI / test (push) Failing after 31s

Profiling the wasm compositor at 1080p idle: ~90 ms per frame in the software rasteriser, run
every loop iteration (92% of a core, stuttery). Now:
- compose_frame compares what the frame is made from (shell ops, decorations, popups, client
  damage) with the last one and returns the previous pixels when nothing changed; the DRM and
  nested loops only present a changed frame (held until the display is ready).
- fill_rounded_rect fills spans (circle test only in the corner bands) and blit_shm_surface
  copies rows without per-pixel calls; tests check both against the old per-pixel code.
- snapshot_shm_buffer sliced buffers byte by byte; now a slice copy.
- --profile prints per-3s step / shell / raster timings.
Idle CPU at 1080p: 92% -> ~10%.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 03:35:06 -08:00
1 parent 235f17cd70
commit 095bbc5906
6 files changed
+303 -36

No files matched your search

+54 -4
View File
@@ -47,6 +47,7 @@ pub fn run(args : Array[String]) -> Int {
let mut gfx_out = ""
let mut windowed = false
let mut serve = false
let mut profile = false
let mut drm = false
let mut width = 1280
let mut height = 720
@@ -66,6 +67,9 @@ pub fn run(args : Array[String]) -> Int {
} else if a == "--drm" {
drm = true
i = i + 1
} else if a == "--profile" {
profile = true
i = i + 1
} else if a == "--serve" {
serve = true
i = i + 1
@@ -166,8 +170,16 @@ pub fn run(args : Array[String]) -> Int {
}
@sys.log("moon-plasma compositor listening on " + socket_path)
let mut frames = 0
// A changed frame waits here until the display can take it (no page flip in flight).
let mut need_present = true
// --profile: every 3 s print how long each frame part took on average.
let mut p_t0 = @sys.monotonic_ms()
let mut p_n = 0
let mut p_step = 0UL
let mut p_comp = 0UL
while true {
frames = frames + 1
let f0 = @sys.monotonic_ms()
match kms {
Some(k) => {
if !k.poll() || comp.quit_requested {
@@ -178,9 +190,28 @@ pub fn run(args : Array[String]) -> Int {
comp.handle_input(ev, now_ms)
}
comp.step()
let f1 = @sys.monotonic_ms()
k.set_cursor_shape(comp.desired_cursor())
if k.frame_ready() {
k.present(comp.present_to_gfx(gfx_ctx))
let px = comp.compose_frame()
need_present = need_present || comp.frame_changed
if need_present && k.frame_ready() {
k.present(px)
need_present = false
}
if profile {
p_n = p_n + 1
p_step = p_step + (f1 - f0)
p_comp = p_comp + (@sys.monotonic_ms() - f1)
let now = @sys.monotonic_ms()
if now - p_t0 >= 3000UL {
@sys.log("profile: " + p_n.to_string() + " frames/3s step " + p_step.to_string() + " ms compose+present " + p_comp.to_string() + " ms (shell " + comp.prof_shell_ms.to_string() + " ms, raster " + comp.prof_raster_ms.to_string() + " ms)")
p_t0 = now
p_n = 0
p_step = 0UL
p_comp = 0UL
comp.prof_shell_ms = 0UL
comp.prof_raster_ms = 0UL
}
}
@sys.sleep_ms(8)
continue
@@ -188,6 +219,7 @@ pub fn run(args : Array[String]) -> Int {
None => ()
}
comp.step()
let f1 = @sys.monotonic_ms()
if comp.quit_requested {
break
}
@@ -204,8 +236,11 @@ pub fn run(args : Array[String]) -> Int {
comp.handle_input(ev, now_ms)
}
n.set_cursor_shape(comp.desired_cursor())
if n.frame_ready() {
n.present(comp.present_to_gfx(gfx_ctx))
let px = comp.compose_frame()
need_present = need_present || comp.frame_changed
if need_present && n.frame_ready() {
n.present(px)
need_present = false
}
}
None => {
@@ -216,6 +251,21 @@ pub fn run(args : Array[String]) -> Int {
}
}
}
if profile {
p_n = p_n + 1
p_step = p_step + (f1 - f0)
p_comp = p_comp + (@sys.monotonic_ms() - f1)
let now = @sys.monotonic_ms()
if now - p_t0 >= 3000UL {
@sys.log("profile: " + p_n.to_string() + " frames/3s step " + p_step.to_string() + " ms compose+present " + p_comp.to_string() + " ms (shell " + comp.prof_shell_ms.to_string() + " ms, raster " + comp.prof_raster_ms.to_string() + " ms)")
p_t0 = now
p_n = 0
p_step = 0UL
p_comp = 0UL
comp.prof_shell_ms = 0UL
comp.prof_raster_ms = 0UL
}
}
@sys.sleep_ms(16)
}
match kms {