Smoother on Xorg and Live Starfield: draw one frame ahead, cache a backdrop's unchanging start
CI / test (push) Successful in 2m33s

Tested on a Vast GTX 1650 rig (8-core Xeon E5-2620 v4, NVIDIA Xorg, --x11 --fullscreen):
GPU detection says hardware (nvidia), CHANDRA_RENDER=software switches.

- Frame pacing: at most one frame is drawn ahead of the output instead of waiting until the
  output is ready. Waiting serialised drawing with the X server's copy of the last frame; overview
  on Xorg went from 24-27 fps to 41-48 fps (before the first round: 16-17 fps).
- MoonBit host: a backdrop whose ops change every frame but begin the same (a desktop module:
  Live Starfield's sky and nebulae under moving stars) keeps that common start as cached pixels
  and draws only the rest over a copy of it. Starfield raster 13 -> 1.7 ms a frame and CPU 46% ->
  11% in the cloud; it no longer clears, redraws and re-saves the whole backdrop every frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkTQp5uN5FtwpzrXUA
This commit is contained in:
Claude committed 2026-11-26 03:15:55 +00:00
1 parent 1154437050
commit 02c831576a
3 files changed
+74 -16

No files matched your search

+9 -4
View File
@@ -32,10 +32,15 @@ most ~30 frames a second however often it asks.
## What makes animations smooth everywhere
- Frames are drawn only when the output can take them: on KMS when no page flip is in flight,
nested and on X11 when the previous frame was shown. A frame drawn while one is still on its way
would never be seen (the KMS loop runs at 125 Hz), and it costs a whole frame of CPU. An output
that never says it is ready (a hidden nested window) still gets a frame every 250 ms.
- At most one frame is drawn ahead of the output: while a drawn frame waits for the page flip in
flight (KMS) or for the previous frame to be shown (nested, X11), no other one is drawn. Before,
frames drawn meanwhile were thrown away (the KMS loop runs at 125 Hz), each costing a whole
frame of CPU. Drawing the next frame while the X server copies the last one keeps both busy:
waiting for the copy first halved the frame rate on Xorg. An output that never says it is ready
(a hidden nested window) still gets a frame every 250 ms.
- A backdrop (wallpaper or desktop module) whose ops change every frame but begin the same, like
Live Starfield's sky and nebulae under moving stars, keeps that common start cached as pixels and
draws only the rest over a copy of it (MoonBit host).
- Animations are timed by the clock, so a slow frame makes the next one jump ahead instead of
slowing the animation down.
- The rasteriser blends two colour channels at a time (16-bit lanes, exact division by 255),