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

+51 -3
View File
@@ -53,6 +53,14 @@ pub(all) struct MoonPlasmaCompositor {
mut layout_mode : @wm.LayoutMode
/// Set when the user asked to end the session (the logout button); the main loop then exits.
mut quit_requested : Bool
/// Milliseconds spent so far in the shell (panel modules) and in the rasteriser, for --profile.
/// The last composed frame and what it was made from: an unchanged desktop is not redrawn.
mut last_frame : @renderer.Pixmap?
mut last_sig : FrameSig?
/// True when the frame returned by the latest compose_frame differs from the one before it.
mut frame_changed : Bool
mut prof_shell_ms : UInt64
mut prof_raster_ms : UInt64
}
///|
@@ -102,6 +110,11 @@ pub fn MoonPlasmaCompositor::new(
super_solo: false,
layout_mode: @wm.LayoutMode::Tiling,
quit_requested: false,
last_frame: None,
last_sig: None,
frame_changed: true,
prof_shell_ms: 0UL,
prof_raster_ms: 0UL,
})
}
@@ -111,6 +124,15 @@ pub fn MoonPlasmaCompositor::close(self : MoonPlasmaCompositor) -> Unit {
self.server.close()
}
///| What a frame was drawn from, compared with the next frame's to see whether it changed.
#derive(Eq)
pub(all) struct FrameSig {
bg : Array[@scene.DrawOp]
panel : Array[@scene.DrawOp]
wins : Array[(UInt64, @scene.Rect, Bool, Bool, Array[@scene.DrawOp])]
popups : Array[@scene.Rect]
}
///|
fn MoonPlasmaCompositor::apply_actions(
self : MoonPlasmaCompositor,
@@ -433,12 +455,36 @@ pub fn MoonPlasmaCompositor::compose_frame(
}
}
self.shell.win_list = entries
let t0 = @sys.monotonic_ms()
let (bg_ops, panel_ops) = self.shell.render(self.output_w, self.output_h, self.theme)
self.run_shell_actions()
scene.background_ops = bg_ops
scene.panel_ops = panel_ops
ignore(self.damage.take_damage(self.output_w, self.output_h))
@renderer.render_scene(scene)
let damaged = self.damage.take_damage(self.output_w, self.output_h).length() > 0
let sig : FrameSig = {
bg: bg_ops,
panel: panel_ops,
wins: scene.windows.map(w => (w.id, w.geometry, w.focused, w.fullscreen, w.deco_ops)),
popups: scene.popups.map(p => p.0),
}
// Nothing changed since the last frame (no client commit, same shell and decoration ops):
// hand back the previous pixels instead of rasterising 2 million pixels again.
match (self.last_frame, self.last_sig) {
(Some(prev), Some(ps)) =>
if !damaged && ps == sig {
self.frame_changed = false
return prev
}
_ => ()
}
self.frame_changed = true
self.last_sig = Some(sig)
let t1 = @sys.monotonic_ms()
let px = @renderer.render_scene(scene)
self.last_frame = Some(px)
self.prof_shell_ms = self.prof_shell_ms + (t1 - t0)
self.prof_raster_ms = self.prof_raster_ms + (@sys.monotonic_ms() - t1)
px
}
///|
@@ -449,7 +495,9 @@ pub fn MoonPlasmaCompositor::present_to_gfx(
ctx : @gfx.SurfaceFrameBufferContext,
) -> @renderer.Pixmap {
let pixmap = self.compose_frame()
@gfx.present_pixmap(ctx, pixmap)
if self.frame_changed {
@gfx.present_pixmap(ctx, pixmap)
}
pixmap
}