Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Frame cost, steps 4-6 and 8 (pixel-identical): GPU layer without the hole loop when the window has no app surfaces, transform-only setStyle without the node's own layout pass, __lordTick without walking every timer, fewer pointless React prop updates; golden drag test extended (across 0, a removed child, 200 %); LordBench's square and the Cooling fans now turn (the 'rotate' key, approved 2026-10-28)

Federico Pereira9b5a69df63a8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f16d830..2ce664b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -201,6 +201,19 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
architecture's): any change to a frame fails. The test also prints how many pixels differ from a full repaint:
today at most 2,265 per frame on the CPU path, with black pixels at the dragged window's rounded top corners, and
70,940 on the GPU path, one level darker in the window's shadow. About 11 s on VM 116.
+ - **Three more runs** (the test's cases a reviewer found missing): `neg`, the window starting at (−200, −120) and
+ moving 6 px right and 4 px down a frame, so its left edge crosses x = 0 and its top y = 0 while the square turns;
+ `remove`, a badge inside the window removed (`node_detach`) at frame 35, after frames that only copy the layer
+ (the square turns every 10th frame), then the square turning again at frame 40; and `k2`, the whole drag on a
+ 2048×1280 display at 200 %. These three add a column of boxes with odd widths, shadows and text centered at half
+ pixels. Their 183 hashes per path were written by `make drag-golden` on 001633b's code (the four functions the
+ test calls that 001633b lacks, `node_restyled`, `paint_root_clear`, `paint_root_full` and `paint_layer_parts`,
+ added beside it unchanged or as a no-op count; the first five runs' 725 hashes came out identical to the
+ committed ones, which checks that), and the current code passes all 908 on both paths. Each run catches a change
+ the first five miss (checked by breaking the code on purpose): partial repaints across x = 0 (`neg`, 42 of 61
+ frames), a node's part trusted after outside damage mapped through a stale `layer.at` (`remove`, 20 frames from
+ frame 40) and a part's box computed without the display scale (`k2`, 59 frames). The whole of `engine-test` takes
+ about 15 s on VM 116 (11 s before).
- **`LORD_PAINT_VERIFY=N`** (lord-server's environment): every N-th frame of each display is compared with a full
repaint of the tree into a scratch canvas (`paint_root_full`: no drag layer, no copy of what is below it, no
skipped node; the GPU path's list of app windows is kept), and the count of differing pixels goes to stderr.
@@ -211,7 +224,7 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
### Changed
-- **Less work in a dragged window's frame, same pixels** (in development for 0.8.6; the first two steps of making a
+- **Less work in a dragged window's frame, same pixels** (in development for 0.8.6; the first steps of making a
drag frame cheaper on the Raspberry Pi). Every frame of `test_drag_exact` keeps its golden hash on the CPU and GPU
paths (VM 116, x86_64); the time saved has not been measured yet.
- **No clear under the copy of what is below the window:** `paint_root_clear` (`ui/paint.c`) replaces
@@ -232,9 +245,74 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
whose em isn't a power of two of at most 2048 units, as Inter's is (`text_drew_inexact`), an unchanged transformed node, an app window or a video inside
(`layer_part_exact`, `layer_note_exact`). A transformed node's image steps its bilinear weights from the first
pixel of each row, so a part cutting it on the left would change them; `canvas_affine_watch`/`canvas_affine_cut`
- (`canvas.c`) report that and the layer is painted whole. In `test_drag_exact` 606 of the 611 layer renders are now
- parts (before: 6, the terminal's); the other 5 are each run's first. Every golden hash is unchanged on both paths.
+ (`canvas.c`) report that and the layer is painted whole. In `test_drag_exact`'s first five runs 366 of the 611
+ layer renders are now parts (before: 6, the terminal's), and 438 of 738 with the three runs added later. Every golden hash is unchanged on both paths.
With neither the margin nor the watch, 160 frames per path fail; with the watch but no margin, they all pass.
+ - **GPU path: no app-hole walk for a window without app windows, and a faster sentinel fill** (`ui/paint.c`). The
+ layer's hole map now carries a flag, `layer.has_holes`, that is 0 only while the map stands for all zeros; then
+ `layer_holes` only turns the sentinel back into 0 (it no longer writes zeros over zeros) and `layer_paint` skips
+ the per-pixel walk that reopens app holes over the blit, which for a window with no app surface never wrote
+ anything. The flag is recomputed from what a whole-map pass wrote, a part pass can only raise it, and a part that
+ brings the first hole into a map that had none zeroes the rest of the map first, so the map is byte for byte what
+ the old code would have read. `layer_fill` fills one row with the sentinel and copies it to the others. Checked:
+ the golden hashes (GPU path), and a differential run of the frame against 001633b's `paint.c` with an app window
+ inside the dragged window (half of it an alpha-0 hole), present from the start and removed at frame 60, or
+ appended at frame 40, identical on both paths over 3,874 frame hashes; with the walk always skipped, 139 of them
+ differ.
+ - **A setStyle that only turns or scales a node no longer lays that node out again** (`node_restyled` in
+ `ui/node.c`). When the only change is `rotate`, `scaleX`, `scaleY` or `transformOriginX/Y` (what
+ `runtime/style.js` makes of a `transform`), the node already had its `StyleExt`, it isn't a text node and has no
+ text node above it, and its subtree has no text or image (at most 256 nodes), the node is marked for repaint and
+ placed again by its parent (`node_moved`) instead of `node_invalidate`: its own layout pass and the measure flags
+ are kept. That gives the same layout by construction: layout never reads the transform, `place()` computes every
+ node's matrix on each `layout_root`, the measure flag is read only by text nodes, and a subtree without text or
+ images lays out from styles and sizes alone. Its ancestors are still laid out again, as before, so the saving is
+ only that node's own pass (small: LordBench's square has one child). `setStyle(n, 'transform', …)` is
+ still not a key `lord.setStyle` takes and still changes and marks nothing. Checked by `test_transform_restyle` (`engine-test`): two copies of a tree, one through `node_restyled`
+ and one through `node_invalidate`, 120 frames of turns and scales on five nodes (a leaf, one with boxes inside,
+ one with text inside, one under a text node, one sized by flex) mixed with a column width moving by 0.3 px, a font
+ size and a root width moving by 0.2 px: every node's box, absolute position, matrices and text measure, and
+ every pixel, are equal; the 'transform' key changes nothing. The golden hashes are unchanged (the drag's square
+ now takes this path) and the frame against 001633b's `f_set_style` logic is identical in the differential run.
+ - **The JS timers no longer look at every pending timer on each pass of the main loop** (`ui/js_prelude.h`, the
+ polyfills moved out of `ui/js.c` unchanged otherwise). `__lordTick` keeps the earliest deadline (`minAt`, lowered
+ by every `setTimeout`/`setInterval`/`setImmediate`) and returns at once when nothing is due; when something is,
+ one pass collects the due timers without building an `[id, timer]` pair per timer and computes the next deadline.
+ Due timers still run by deadline, then by id, each at most once per tick, a timer set during the tick waits for
+ the next one, and one cleared before its turn doesn't run. Clearing the earliest timer marks `minAt` stale and it
+ is computed again before it is used, so the wait the tick returns to the main loop is the same number, not only
+ the same order. lord-server also makes the atoms of `__lordTick`, `__lordWantsFrame` and `__lordFrame` once per
+ runtime (`call_hot`) instead of on every call; the function is still looked up each time, so the recovery
+ screen's replacements are the ones run. Checked by `build/timer-order-test` (`make -C server test`): 400 seeded
+ random scripts run on this prelude and on 001633b's, in QuickJS, with timeouts, intervals and immediates at
+ equal, zero, negative, fractional, NaN and string delays, clears of pending, due, fired, unknown and string ids,
+ timers set and cleared from inside callbacks, callbacks that throw, and ticks whose `now` is behind the clock
+ `lord.now()` reads (a clock that moves on every read, so both must also read it the same number of times):
+ 427,538 callbacks and 21.6 MB of trace (what runs, in which order, with which arguments, every value the tick
+ returns as `%.17g`, and what is logged) are identical. Breaking the code on purpose fails it: firing by id alone,
+ 400 of 400 scripts differ; not recomputing after the earliest timer is cleared, 397. A tick with 200 timers
+ pending and none due: 158.75 µs before, 0.30 µs now (`build/timer-order-test bench`, VM 116, x86_64).
+ - **Fewer React renders and style conversions that change nothing** (`runtime/index.js`,
+ `apps/sysinfo/performance.jsx`). `applyProps` keeps, per node (a `WeakMap`, so the instance a ref sees is
+ unchanged), a copy of the flattened style it last converted, as keys and values in their order, and only when
+ every value is a primitive and no converted value is NaN. A render whose flattened style has the same keys in the
+ same order with the same values (`Object.is`) skips `normalize` and `applyStyle`: `normalize` is pure (no
+ direction, theme or state), so it would give an equal style and `applyStyle` would send no call. A style object
+ changed in place is still seen (the copy is compared, not the object), a different key order is not skipped
+ (later keys override earlier ones: `margin` then `marginTop`), and a NaN (a bad `#zz` color, a gradient without
+ an angle) keeps the old behaviour of re-sending that property on every render. Object values (a `transform`
+ list) are never skipped. LordBench's Performance view no longer re-renders on a 500 ms poll that brings the same
+ state, mode, step and progress as the last one (a result or a start error always counts as new). Checked by
+ `tests/runtime_props_test.mjs` (`make -C server test`; needs node and `node_modules`, so it is skipped on VM 116,
+ which has no node): fuzzed trees of 24 nodes (views, texts, images, an `Activity` that hides and shows half of
+ them, reorders and removals) over 8 seeds × 300 renders, with styles kept as the same object, copied, changed in
+ place, reordered, partly undefined, as arrays, with NaN, −0, overrides and transforms. The bundle with the skip and
+ the same bundle with it turned off send identical `lord.*` call sequences and end with identical styles (72,322
+ lines; 31,498 of 53,311 `applyProps` calls skipped; on the Mac). Breaking the skip on purpose fails it: without
+ the NaN rule all 8 seeds differ; in scratch runs, comparing keys without their order 6 of 6 seeds and comparing
+ the props' object instead of a copy 3 of 3. The Performance view rendered with a scripted run (waiting, three
+ steps, a mode change, cancelled) gives the same native call log with 001633b's view and this one, with 146
+ instead of 356 `applyProps` calls. No C code changed; the golden hashes and `engine-test` pass as before.
### Fixed
@@ -333,6 +411,14 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
to 11 rectangles and this one gives one is not investigated.
LordBench's desktop mode in the headless harness (three runs each): 58.9-60.0 fps, build p50 1.25-1.26 ms and p99
5.9-7.6 ms before; 60.0 fps, p50 1.24-1.27 ms and p99 5.95-6.32 ms after.
+- **LordBench's turning square and the Cooling page's fans now turn** (approved by the maintainer on 2026-10-28).
+ `apps/sysinfo/scene.jsx` and `sdk/cooling.jsx` called `lord.setStyle(n, 'transform', 'rotate(…deg)')`, and
+ `transform` is not a key the engine takes (it only logged `js: unsupported style 'transform'`), so the desktop
+ test's square never turned and the fans only jumped when React rendered them. They now send the engine's own
+ `rotate` key in degrees (the fans keep `toFixed(1)`, the same angle React sends). The desktop test's window is no
+ longer static: its layer is repainted (in part, where exact) every frame, so desktop-test numbers from before this
+ change measured a lighter scene and aren't comparable.
+
- **The desktop under load** (found by LordBench's desktop test; `docs/BENCHMARK.md`, "The desktop under load"): the
compositor's cgroup (`server`) had the same `cpu.weight` as every app scope, and nice values don't count between
cgroups, so an app keeping every core busy took half of the compositor's CPU even at nice 19. On a Raspberry Pi 5
diff --git a/apps/sysinfo/performance.jsx b/apps/sysinfo/performance.jsx
index ba0ca24..8ebaa05 100644
--- a/apps/sysinfo/performance.jsx
+++ b/apps/sysinfo/performance.jsx
@@ -27,6 +27,14 @@ function fmt(v) {
return formatNumber(v, v >= 100 ? 0 : v >= 10 ? 1 : 2);
}
+// A poll that shows nothing new: the same keys with the same primitive values (state, mode, step,
+// progress; a result or a start error always counts as new). Most 500 ms polls are this while a
+// step runs, and keeping the old state then spares a render of the whole view.
+function samePoll(a, b) {
+ const ka = Object.keys(a), kb = Object.keys(b);
+ return ka.length === kb.length && ka.every((k, i) => k === kb[i] && a[k] === b[k] && (a[k] === null || typeof a[k] !== 'object'));
+}
+
function useBench() {
const [st, setSt] = useState(() => {
let p = null;
@@ -36,7 +44,7 @@ function useBench() {
const running = st.state === 'waiting' || st.state === 'running';
useEffect(() => {
if (!running) return undefined;
- const id = setInterval(() => { try { const p = bench().poll(); if (p) setSt(p); } catch (e) { /* keep the last */ } }, 500);
+ const id = setInterval(() => { try { const p = bench().poll(); if (p) setSt((x) => (samePoll(x, p) ? x : p)); } catch (e) { /* keep the last */ } }, 500);
return () => clearInterval(id);
}, [running]);
const start = (mode) => {
diff --git a/apps/sysinfo/scene.jsx b/apps/sysinfo/scene.jsx
index 31bb8c3..2bb20bc 100644
--- a/apps/sysinfo/scene.jsx
+++ b/apps/sysinfo/scene.jsx
@@ -41,7 +41,7 @@ export function Scene() {
const step = () => {
a = (a + 6) % 360;
const n = spin.current && spin.current.id;
- if (n != null) try { lord.setStyle(n, 'transform', `rotate(${a}deg)`); } catch (e) { /* gone */ }
+ if (n != null) try { lord.setStyle(n, 'rotate', a); } catch (e) { /* gone */ }
tm = setTimeout(step, TICK_MS);
};
tm = setTimeout(step, TICK_MS);
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 28489fe..06b48fe 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -74,6 +74,12 @@ like React Native but on top of our display server.
1. An event arrives (evdev) → `hit_test` finds the node under the cursor → `__lordEvent` in JS.
2. React updates state → the reconciler calls `lord.setStyle/appendChild/...` → nodes are marked.
+ Only the style properties that changed are sent (`applyStyle` in `runtime/style.js`). Since 0.8.6
+ (in development) `applyProps` in `runtime/index.js` also skips converting a node's style when its
+ flattened style has the same keys, in the same order, with the same primitive values as last time
+ (kept as a copy, so a style object changed in place is still seen; not when a converted value is
+ NaN, which `applyStyle` re-sends every time). The calls are exactly the ones it sent before:
+ `server/tests/runtime_props_test.mjs` checks it against the runtime with the skip turned off.
3. `lord-server` recomputes the layout, computes the damaged region and repaints only that region.
4. It copies the scene to the back buffer, draws the cursor, and page-flips on the next vblank.
diff --git a/docs/THEMES-GUIDE.md b/docs/THEMES-GUIDE.md
index 2296a75..b1ed2f3 100644
--- a/docs/THEMES-GUIDE.md
+++ b/docs/THEMES-GUIDE.md
@@ -366,10 +366,11 @@ Everything runs on `lord-server`'s main thread, which also composites the screen
Linux apps. A slow theme makes the whole desktop slow.
- **No React render per frame.** Moving and resizing windows is already in C. To animate, change one
- style with **`lord.setStyle(ref.current.id, 'opacity' | 'transform' | …, value)`** from a timer or
+ style with **`lord.setStyle(ref.current.id, 'opacity' | 'rotate' | 'scaleX' | …, value)`** from a timer or
`requestAnimationFrame` (the `ScrollView` thumb fade in `sdk/components.jsx`, the fans in
`sdk/cooling.jsx`); stop the loop when the animation ends or the surface is hidden, and don't start
- it with reduce motion.
+ it with reduce motion. `lord.setStyle` takes the engine's own keys (`rotate` in degrees, `scaleX`,
+ `scaleY`), not a CSS `transform` string: an unknown key changes nothing and is logged once.
- **`transform` scale and rotate are cheap**: the subtree is painted once into a cached raster and
composited (Lord Flow's minimize effect scales a whole window).
- **Blur costs**: `backdropFilter: blur(r)` reads a margin of 2×r around the surface, and any change
@@ -500,7 +501,7 @@ Lord Classic installed: they are the fallback (`start_theme` in `main.c`).
- Sessions started by `lord-sessiond` write their log to **`~/.cache/lordos/session.log`** (the login
screen to `greeter.log`); a standalone `lord-server` writes to the terminal it was started from.
- `console.log`, `.info`, `.debug` → `js: …` lines; `console.warn` → `js: [warn] …`;
- `console.error` → `js: [error] …` (the prelude in `server/src/ui/js.c`). Exceptions in timers
+ `console.error` → `js: [error] …` (the prelude in `server/src/ui/js_prelude.h`). Exceptions in timers
and animation frames are logged as `js: [error] timer: …` / `raf: …`.
- Useful lines: `js: theme <path> loaded in N ms (K KB)`, `code: …` (the verified-code state and each
check or refusal), `lord-server: cambiando a tema <path>` (a switch), `js: unsupported style '<key>'`.
diff --git a/docs/WINDOWS.md b/docs/WINDOWS.md
index badc180..36e06f8 100644
--- a/docs/WINDOWS.md
+++ b/docs/WINDOWS.md
@@ -107,6 +107,11 @@ wm.beginResize(id, edges) // edges as in xdg_toplevel.resize: 1 top, 2 botto
- the layer remembers where the app holes are: exact alpha 0, distinguished from an empty
background thanks to a sentinel value. They are reopened over the blend and the app is recorded
at its new place (`wl_paint_holes(0)`).
+ - a window with no app surface skips that work (0.8.6, in development): `layer.has_holes` is 0
+ only while the hole map stands for all zeros, so `layer_holes` just turns the sentinel back into
+ 0 and `layer_paint` doesn't walk the map. A part that brings the first hole into such a map zeroes
+ the rest of it first, so what is read is always what the full walk would have written. The
+ sentinel fill writes one row and copies it.
- **There's no layer** if there is a backdrop blur inside (`backdropFilter`), or a video on the GPU
path.
- **A `canvas_blit` detail:** opaque pixels are copied directly (same result as blending, without
@@ -115,12 +120,18 @@ wm.beginResize(id, edges) // edges as in xdg_toplevel.resize: 1 top, 2 botto
### Checking it (0.8.6, in development)
- **`test_drag_exact`** (`server/tests/engine_test.c`, run by `make -C server test`) drags LordBench's
- desktop scene along its figure of eight for 480 frames, plus four short runs (a text that resizes a
+ desktop scene along its figure of eight for 480 frames, plus seven short runs (a text that resizes a
child, a child moving inside the window, a terminal's blinking cursor, a square turning across the
- window's edge), on the CPU path and on the GPU path's canvas. Every frame's hash must match
+ window's edge, the window crossing x = 0 and y = 0 while the square turns, a child removed after
+ frames that only copy the layer and then the square turning again, and the drag on a display at
+ 200 %; the last three with boxes and text at half pixels), on the CPU path and on the GPU path's
+ canvas. Every frame's hash must match
`server/tests/drag_golden_cpu.txt` and `drag_golden_gpu.txt`, written from the code before any change
to this path: a faster frame has to give exactly the same pixels. The hashes are per architecture
- (x86_64 so far); `make -C server drag-golden` writes them, only on the reference code.
+ (x86_64 so far); `make -C server drag-golden` writes them, only on the reference code. A run added
+ later gets its hashes the same way: the new test built against 001633b's code (with the few test entry
+ points it lacks added beside it, which must leave the earlier runs' hashes identical), never against
+ the code being checked.
- **Against a full repaint** the test prints a second number, which may only go down: today a drag
frame differs from a full repaint in at most 2,265 pixels on the CPU path (black pixels at the dragged
window's rounded top corners) and 70,940 on the GPU path (one level darker in its shadow).
@@ -232,6 +243,23 @@ was checked against this path:
clears `layout_ok` up to the root) and that gets the same box keeps its children's layout. Moving a
window only changes its `left`/`top` (`grab.c` calls `node_moved`), so a frame of a drag lays out the
desktop's top level and places the rest (`place()`), instead of laying out every window.
+- **A transform-only setStyle keeps the node's layout** (0.8.6, in development; `node_restyled` in
+ `ui/node.c`). A change of only `rotate`, `scaleX`, `scaleY` or `transformOriginX/Y` on a node that
+ already has its `StyleExt`, with no text node above it and no text or image in its subtree, marks
+ it for repaint and has its parent place it again (`node_moved`) instead of `node_invalidate`.
+ Layout never reads the transform and `place()` recomputes every matrix, so the result is the same;
+ only that node's own layout pass is saved (its ancestors are laid out as before).
+ `test_transform_restyle` compares every node's layout and every pixel with the `node_invalidate`
+ path. `'transform'` itself is not a key `lord.setStyle` takes and changes nothing.
+- **A main-loop pass with no timer due doesn't walk the timers** (0.8.6, in development;
+ `ui/js_prelude.h`). `__lordTick` keeps the earliest deadline and returns at once when it hasn't
+ come; when it has, one pass fires the due timers by deadline, then by id, as before. Clearing the
+ earliest timer marks that deadline stale and it is computed again before use, so the wait returned
+ to the main loop is the same number as before. lord-server makes the atoms of the three globals it
+ calls on every pass once per runtime. `build/timer-order-test` runs 400 random timer scripts on this
+ prelude and on the one before it and requires the same trace (callbacks, order, arguments, every
+ returned wait, logs). A tick with 200 timers pending and none due went from 158.75 µs to 0.30 µs
+ (VM 116).
- **Text outside the clip is not laid out** (a list row scrolled away), and a cut "…" is remembered
like a measurement.
- **The node stays small:** the rare styles (per-side edges, per-corner radii, scale/rotate,
diff --git a/runtime/index.js b/runtime/index.js
index 51bc3da..9cda397 100644
--- a/runtime/index.js
+++ b/runtime/index.js
@@ -3,7 +3,7 @@
import Reconciler from 'react-reconciler';
import { ConcurrentRoot, DefaultEventPriority, NoEventPriority } from 'react-reconciler/constants';
import { createContext, useEffect, useState } from 'react';
-import { normalize, applyStyle } from './style.js';
+import { flatten, normalize, applyStyle } from './style.js';
import { register, unregister, currentPriority, addListener } from './events.js';
export { addListener };
@@ -66,10 +66,46 @@ globalThis.__lordScreen = () => {
for (const fn of screenListeners) { try { fn(screen, old); } catch (e) { console.error('pantalla:', e?.message || e); } }
};
+// For each instance, a copy of the flattened style that produced inst.style, as [key, value, key,
+// value, …] in its own order (a WeakMap, so the instance a ref sees is unchanged). It is kept only
+// when every value is a primitive and nothing in inst.style is NaN (null otherwise). A render whose
+// flattened style has the same keys, in the same order, with the same values (Object.is) then skips
+// normalize and sends nothing: normalize is pure, so it would give a style equal to inst.style and
+// applyStyle would send no call. It is a copy, not the props' object, so a style object changed in
+// place is still seen; the NaN rule keeps the calls applyStyle repeats because NaN !== NaN (a bad
+// '#zz' color).
+function flatCopy(flat, style) {
+ const out = [];
+ for (const k in flat) {
+ const v = flat[k];
+ if (v !== null && (typeof v === 'object' || typeof v === 'function')) return null;
+ out.push(k, v);
+ }
+ for (const k in style) {
+ const v = style[k];
+ if (v !== v || (Array.isArray(v) && v.some((x) => x !== x))) return null;
+ }
+ return out;
+}
+const flats = new WeakMap();
+function sameFlat(copy, flat) {
+ if (!copy) return false;
+ let i = 0;
+ for (const k in flat) {
+ if (i >= copy.length || copy[i] !== k || !Object.is(copy[i + 1], flat[k])) return false;
+ i += 2;
+ }
+ return i === copy.length;
+}
+
function applyProps(inst, prev, next) {
- const style = normalize(next.style);
- applyStyle(inst.id, inst.style, style);
- inst.style = style;
+ const flat = flatten(next.style);
+ if (!sameFlat(flats.get(inst), flat)) {
+ const style = normalize(flat);
+ applyStyle(inst.id, inst.style, style);
+ inst.style = style;
+ flats.set(inst, flatCopy(flat, style));
+ }
if (prev.src !== next.src) lord.setProp(inst.id, 'src', next.src ?? null);
if (prev.session !== next.session) lord.setProp(inst.id, 'session', next.session ?? 0);
if (prev.surface !== next.surface) lord.setProp(inst.id, 'surface', next.surface ?? 0);
diff --git a/sdk/cooling.jsx b/sdk/cooling.jsx
index fd849fb..63f3f71 100644
--- a/sdk/cooling.jsx
+++ b/sdk/cooling.jsx
@@ -102,7 +102,7 @@ function useSpin(pct) {
s.v += (target - s.v) * 0.12;
if (target === 0 && s.v < 0.01) { s.v = 0; return; }
s.a = (s.a + s.v * 360 / FPS) % 360;
- for (const [node, k] of s.rotors) call(() => lord.setStyle(node, 'transform', `rotate(${(s.a * k).toFixed(1)}deg)`));
+ for (const [node, k] of s.rotors) call(() => lord.setStyle(node, 'rotate', +(s.a * k).toFixed(1)));
tm = setTimeout(step, 1000 / FPS);
};
tm = setTimeout(step, 1000 / FPS);
diff --git a/server/Makefile b/server/Makefile
index 528e21c..d33570d 100644
--- a/server/Makefile
+++ b/server/Makefile
@@ -254,6 +254,12 @@ build/xwm-test: tests/xwm_test.c src/wl/x11wire.c src/wl/x11wire.h
@mkdir -p build
$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/xwm_test.c src/wl/x11wire.c
./$@ || { rm -f $@; exit 1; }
+# tests/timer_order_test.c: the JS timers (src/ui/js_prelude.h) against the prelude they replaced
+test: build/timer-order-test
+build/timer-order-test: tests/timer_order_test.c src/ui/js_prelude.h $(QJS_OBJ)
+ @mkdir -p build
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/timer_order_test.c $(QJS_OBJ) -lm -lpthread
+ ./$@ || { rm -f $@; exit 1; }
test: build/tzif-test
build/tzif-test: tests/tzif_test.c src/ui/tzif.c src/ui/tzif.h
@mkdir -p build
diff --git a/server/src/ui/js.c b/server/src/ui/js.c
index 143d5f4..eb53ab8 100644
--- a/server/src/ui/js.c
+++ b/server/src/ui/js.c
@@ -47,43 +47,7 @@ static JSRuntime *rt;
static JSContext *ctx;
static void set_screen_displays(JSValue screen);
-/* Minimal polyfills: the real event loop is lord-server's (main.c). */
-static const char prelude[] =
- "(function(){\n"
- "const g = globalThis;\n"
- "const fmt = v => typeof v === 'string' ? v : v instanceof Error ? (v.message + '\\n' + (v.stack || '')) :\n"
- " (() => { try { return JSON.stringify(v); } catch (e) { return String(v); } })();\n"
- "const out = p => (...a) => lord.log(p + a.map(fmt).join(' '));\n"
- "g.console = { log: out(''), info: out(''), debug: out(''), warn: out('[warn] '), error: out('[error] ') };\n"
- "g.performance = { now: () => lord.now() };\n"
- "let nextId = 1; const timers = new Map();\n"
- "const add = (fn, ms, args, repeat) => { const id = nextId++; ms = Math.max(0, +ms || 0);\n"
- " timers.set(id, { fn, args, at: lord.now() + ms, ms, repeat }); return id; };\n"
- "g.setTimeout = (fn, ms, ...a) => add(fn, ms, a, false);\n"
- "g.setInterval = (fn, ms, ...a) => add(fn, ms, a, true);\n"
- "g.setImmediate = (fn, ...a) => add(fn, 0, a, false);\n"
- "g.clearTimeout = g.clearInterval = g.clearImmediate = id => { timers.delete(id); };\n"
- "g.queueMicrotask = fn => { Promise.resolve().then(fn); };\n"
- "let frames = new Map(), frameId = 1;\n"
- "g.requestAnimationFrame = fn => { const id = frameId++; frames.set(id, fn); return id; };\n"
- "g.cancelAnimationFrame = id => { frames.delete(id); };\n"
- "g.__lordTick = now => {\n"
- " const due = [];\n"
- " for (const [id, t] of timers) if (t.at <= now) due.push([id, t]);\n"
- " due.sort((a, b) => a[1].at - b[1].at || a[0] - b[0]);\n"
- " for (const [id, t] of due) {\n"
- " if (!timers.has(id)) continue;\n"
- " if (t.repeat) t.at = now + Math.max(t.ms, 1); else timers.delete(id);\n"
- " try { t.fn(...t.args); } catch (e) { console.error('timer:', e); }\n"
- " }\n"
- " now = lord.now(); let next = -1;\n"
- " for (const t of timers.values()) { const d = Math.max(0, t.at - now); if (next < 0 || d < next) next = d; }\n"
- " return next;\n"
- "};\n"
- "g.__lordWantsFrame = () => frames.size > 0;\n"
- "g.__lordFrame = now => { const f = frames; frames = new Map();\n"
- " for (const fn of f.values()) { try { fn(now); } catch (e) { console.error('raf:', e); } } };\n"
- "})();\n";
+#include "js_prelude.h" /* the polyfills: console, timers, animation frames */
static double now_ms(void) {
struct timespec t;
@@ -353,8 +317,8 @@ static int eval(const char *src, size_t len, const char *name) {
return ok ? 0 : -1;
}
-static JSValue call_global(const char *name, int argc, JSValueConst *argv) {
- JSValue g = JS_GetGlobalObject(ctx), f = JS_GetPropertyStr(ctx, g, name), r = JS_UNDEFINED;
+static JSValue call_global_atom(JSAtom name, int argc, JSValueConst *argv) {
+ JSValue g = JS_GetGlobalObject(ctx), f = JS_GetProperty(ctx, g, name), r = JS_UNDEFINED;
if (JS_IsFunction(ctx, f)) {
r = JS_Call(ctx, f, g, argc, argv);
if (JS_IsException(r)) { dump_exception(ctx); r = JS_UNDEFINED; }
@@ -364,6 +328,28 @@ static JSValue call_global(const char *name, int argc, JSValueConst *argv) {
return r;
}
+static JSValue call_global(const char *name, int argc, JSValueConst *argv) {
+ JSAtom a = JS_NewAtom(ctx, name);
+ JSValue r = call_global_atom(a, argc, argv);
+ JS_FreeAtom(ctx, a);
+ return r;
+}
+
+/* The globals called on every pass of the main loop: their atoms are made once per runtime (the
+ * function is still looked up on each call, so the recovery screen's replacements are the ones run) */
+enum { HOT_TICK, HOT_WANTS_FRAME, HOT_FRAME, HOT_N };
+static const char *const hot_name[HOT_N] = { "__lordTick", "__lordWantsFrame", "__lordFrame" };
+static JSAtom hot_atom[HOT_N];
+static JSRuntime *hot_rt;
+
+static JSValue call_hot(int which, int argc, JSValueConst *argv) {
+ if (hot_rt != rt) {
+ for (int i = 0; i < HOT_N; i++) hot_atom[i] = JS_NewAtom(ctx, hot_name[i]);
+ hot_rt = rt;
+ }
+ return call_global_atom(hot_atom[which], argc, argv);
+}
+
/* Reads a bundle of LordOS's own code through the verified-code check (sec/codesig.c): the bytes
* returned are exactly the ones that were hashed. NULL (and *refused = 1) if it was refused. */
static char *load_code(const char *path, size_t *len, int *refused) {
@@ -594,6 +580,8 @@ int js_app_recovery(void) {
void js_shutdown(void) {
media_shutdown(); /* the lord-media helpers belong to this context */
if (ctx) js_wasm_shutdown(ctx);
+ if (ctx && hot_rt == rt) for (int i = 0; i < HOT_N; i++) JS_FreeAtom(ctx, hot_atom[i]);
+ hot_rt = NULL;
if (ctx) JS_FreeContext(ctx);
if (rt) JS_FreeRuntime(rt);
ctx = NULL;
@@ -602,7 +590,7 @@ void js_shutdown(void) {
double js_tick(double now) {
JSValue arg = JS_NewFloat64(ctx, now);
- JSValue r = call_global("__lordTick", 1, &arg);
+ JSValue r = call_hot(HOT_TICK, 1, &arg);
double next = -1;
JS_ToFloat64(ctx, &next, r);
JS_FreeValue(ctx, r);
@@ -611,7 +599,7 @@ double js_tick(double now) {
}
int js_wants_frame(void) {
- JSValue r = call_global("__lordWantsFrame", 0, NULL);
+ JSValue r = call_hot(HOT_WANTS_FRAME, 0, NULL);
int w = JS_ToBool(ctx, r);
JS_FreeValue(ctx, r);
return w;
@@ -619,7 +607,7 @@ int js_wants_frame(void) {
void js_frame(double now) {
JSValue arg = JS_NewFloat64(ctx, now);
- JS_FreeValue(ctx, call_global("__lordFrame", 1, &arg));
+ JS_FreeValue(ctx, call_hot(HOT_FRAME, 1, &arg));
drain_jobs();
}
diff --git a/server/src/ui/js_prelude.h b/server/src/ui/js_prelude.h
new file mode 100644
index 0000000..31b742a
--- /dev/null
+++ b/server/src/ui/js_prelude.h
@@ -0,0 +1,61 @@
+/* js_prelude.h — the JS polyfills evaluated before any bundle (console, timers, animation frames).
+ * Only ui/js.c includes it, and tests/timer_order_test.c, which checks the timers against the
+ * algorithm of 0.8.6's first build (the same callbacks in the same order, the same waits).
+ *
+ * The real event loop is lord-server's (main.c): it calls __lordTick(now) and sleeps for what it
+ * returns (ms until the next timer, -1 with none). Due timers run by their deadline, then by id
+ * (the order they were set), each at most once per tick; one set while the tick runs waits for the
+ * next tick, as does one cleared before its turn. minAt is the earliest deadline, so a tick with
+ * nothing due returns without looking at the timers: it is exact except after clearing the
+ * earliest one (stale), and then it is computed again before it is used. */
+#ifndef LORD_JS_PRELUDE_H
+#define LORD_JS_PRELUDE_H
+
+static const char prelude[] =
+ "(function(){\n"
+ "const g = globalThis;\n"
+ "const fmt = v => typeof v === 'string' ? v : v instanceof Error ? (v.message + '\\n' + (v.stack || '')) :\n"
+ " (() => { try { return JSON.stringify(v); } catch (e) { return String(v); } })();\n"
+ "const out = p => (...a) => lord.log(p + a.map(fmt).join(' '));\n"
+ "g.console = { log: out(''), info: out(''), debug: out(''), warn: out('[warn] '), error: out('[error] ') };\n"
+ "g.performance = { now: () => lord.now() };\n"
+ "let nextId = 1; const timers = new Map();\n"
+ "let minAt = Infinity, stale = false;\n"
+ "const add = (fn, ms, args, repeat) => { const id = nextId++; ms = Math.max(0, +ms || 0);\n"
+ " const at = lord.now() + ms; timers.set(id, { id, fn, args, at, ms, repeat });\n"
+ " if (at < minAt) minAt = at; return id; };\n"
+ "g.setTimeout = (fn, ms, ...a) => add(fn, ms, a, false);\n"
+ "g.setInterval = (fn, ms, ...a) => add(fn, ms, a, true);\n"
+ "g.setImmediate = (fn, ...a) => add(fn, 0, a, false);\n"
+ "g.clearTimeout = g.clearInterval = g.clearImmediate = id => {\n"
+ " const t = timers.get(id); if (t === undefined) return;\n"
+ " timers.delete(id); if (t.at <= minAt) stale = true; };\n"
+ "const lowest = () => { let m = Infinity; for (const t of timers.values()) if (t.at < m) m = t.at; minAt = m; stale = false; };\n"
+ "g.queueMicrotask = fn => { Promise.resolve().then(fn); };\n"
+ "let frames = new Map(), frameId = 1;\n"
+ "g.requestAnimationFrame = fn => { const id = frameId++; frames.set(id, fn); return id; };\n"
+ "g.cancelAnimationFrame = id => { frames.delete(id); };\n"
+ "g.__lordTick = now => {\n"
+ " if (stale) lowest();\n"
+ " if (now >= minAt) {\n"
+ /* minAt leaves out the due ones from here on: each is fired (a repeating one comes back with
+ * its new deadline) or cleared before the loop ends */
+ " const due = []; let m = Infinity;\n"
+ " for (const t of timers.values()) if (t.at <= now) due.push(t); else if (t.at < m) m = t.at;\n"
+ " minAt = m;\n"
+ " due.sort((a, b) => a.at - b.at || a.id - b.id);\n"
+ " for (const t of due) {\n"
+ " if (!timers.has(t.id)) continue;\n"
+ " if (t.repeat) { t.at = now + Math.max(t.ms, 1); if (t.at < minAt) minAt = t.at; } else timers.delete(t.id);\n"
+ " try { t.fn(...t.args); } catch (e) { console.error('timer:', e); }\n"
+ " }\n"
+ " }\n"
+ " if (stale) lowest();\n"
+ " const n = lord.now(); return timers.size ? Math.max(0, minAt - n) : -1;\n"
+ "};\n"
+ "g.__lordWantsFrame = () => frames.size > 0;\n"
+ "g.__lordFrame = now => { const f = frames; frames = new Map();\n"
+ " for (const fn of f.values()) { try { fn(now); } catch (e) { console.error('raf:', e); } } };\n"
+ "})();\n";
+
+#endif
diff --git a/server/src/ui/node.c b/server/src/ui/node.c
index 8c26dd5..529981e 100644
--- a/server/src/ui/node.c
+++ b/server/src/ui/node.c
@@ -126,6 +126,36 @@ void node_invalidate(Node *n) {
invalidate_measure(n);
}
+/* Whether laying n out again would give what it already has: no text (its measure is cached within
+ * half a pixel of the width asked for) and no image (its size comes from the decoded file) in its
+ * subtree; everything else is computed from styles and sizes, which a change would have marked. */
+static int layout_pure(const Node *n, int *budget) {
+ if (n->type == NODE_TEXT || n->type == NODE_IMAGE || --*budget < 0) return 0;
+ for (const Node *c = n->first; c; c = c->next) if (!layout_pure(c, budget)) return 0;
+ return 1;
+}
+
+/* Only rotate, scaleX/Y or transformOrigin changed (what runtime/style.js makes of a transform: a
+ * spinner turning). Layout never reads them and place() computes every node's matrix on each
+ * layout_root, so node_invalidate's work that this skips gives the same results: the measure flag
+ * is read only by text nodes (none on the way up) and n's own layout pass is a pure one (layout_pure). */
+static int transform_only(const Node *n, const Style *before, const StyleExt *xb) {
+ if (!xb || !n->s.ext || n->type == NODE_RAW || n->type == NODE_TEXT) return 0;
+ if (memcmp(before, &n->s, sizeof *before)) return 0; /* the same StyleExt, too */
+ StyleExt x;
+ const StyleExt *now = n->s.ext;
+ memcpy(&x, now, STYLE_EXT_VALUES);
+ memcpy(&x.scale_x, &xb->scale_x, sizeof x.scale_x);
+ memcpy(&x.scale_y, &xb->scale_y, sizeof x.scale_y);
+ memcpy(&x.rotate, &xb->rotate, sizeof x.rotate);
+ memcpy(&x.origin_x, &xb->origin_x, sizeof x.origin_x);
+ memcpy(&x.origin_y, &xb->origin_y, sizeof x.origin_y);
+ if (memcmp(&x, xb, STYLE_EXT_VALUES)) return 0;
+ for (const Node *p = n->parent; p; p = p->parent) if (p->type == NODE_TEXT) return 0;
+ int budget = 256;
+ return layout_pure(n, &budget);
+}
+
void node_restyled(Node *n, const Style *before, const StyleExt *ext_before) {
/* the same value (e.g. React confirms the position left by a drag in C): nothing to repaint */
int ext_changed = n->s.ext && (!before->ext || memcmp(ext_before, n->s.ext, STYLE_EXT_VALUES));
@@ -137,7 +167,12 @@ void node_restyled(Node *n, const Style *before, const StyleExt *ext_before) {
Style moved = *before;
memcpy(moved.pos, n->s.pos, sizeof moved.pos);
if (!ext_changed && n->s.absolute && before->absolute && !memcmp(&moved, &n->s, sizeof moved)) node_moved(n);
- else node_invalidate(n);
+ else if (transform_only(n, before, ext_before)) {
+ /* repainted, placed again by its parent; its own layout and every measure are kept */
+ n->paint_dirty = 1;
+ n->s.ext->r.ok = 0;
+ node_moved(n);
+ } else node_invalidate(n);
}
}
diff --git a/server/src/ui/paint.c b/server/src/ui/paint.c
index 875af8f..9b5504d 100644
--- a/server/src/ui/paint.c
+++ b/server/src/ui/paint.c
@@ -458,6 +458,7 @@ static struct {
Box part; /* parte de la capa a repintar (coordenadas de la capa), p. ej. el cursor de la terminal */
int resize; /* cambiando el tamaño: sin capa, solo lo de abajo */
uint8_t *hole; /* camino GPU: dónde la capa tiene el hueco de una app (alfa 0 de verdad) */
+ int has_holes; /* 0: every byte of hole is 0 (no app surface in the window) */
int painted; /* la capa se pintó en este cuadro (las apps ya quedaron anotadas) */
/* a node inside the window changed: layer.part also holds its boxes (layer_tree_part) */
int tree_part;
@@ -530,12 +531,15 @@ static void subtree_box(Node *n, Box *b, int *ok) {
* hueco de una app (canvas_clear deja 0) de lo que quedó vacío o las esquinas redondeadas. */
#define SENTINEL 0x01000000u
static void layer_fill(int x0, int y0, int x1, int y1) {
- uint32_t v = gpu_active() ? SENTINEL : 0;
- for (int y = y0; y < y1; y++) {
- uint32_t *row = layer.px + (size_t)y * layer.w;
- if (!v) memset(row + x0, 0, (size_t)(x1 - x0) * 4);
- else for (int x = x0; x < x1; x++) row[x] = v;
+ if (x0 >= x1 || y0 >= y1) return;
+ size_t bytes = (size_t)(x1 - x0) * 4;
+ uint32_t *first = layer.px + (size_t)y0 * layer.w + x0;
+ if (!gpu_active()) {
+ for (int y = y0; y < y1; y++) memset(layer.px + (size_t)y * layer.w + x0, 0, bytes);
+ return;
}
+ for (int x = 0; x < x1 - x0; x++) first[x] = SENTINEL; /* one row, then copied */
+ for (int y = y0 + 1; y < y1; y++) memcpy(layer.px + (size_t)y * layer.w + x0, first, bytes);
}
/* Where the window's app surfaces are, in layer pixels: only there can a 0 pixel be an app's hole.
* Elsewhere a 0 is what a rounded clip left outside its corner, and taking it for a hole made the
@@ -558,16 +562,33 @@ static int in_surface(int x, int y) {
for (int i = 0; i < nlsurf; i++) if (x >= lsurf[i].x0 && x < lsurf[i].x1 && y >= lsurf[i].y0 && y < lsurf[i].y1) return 1;
return 0;
}
+/* layer.has_holes == 0 stands for a map of zeros, which is what the loop below writes for a window
+ * with no app surfaces: then it neither writes the map nor does layer_paint walk it. The bytes it
+ * left are made zeros only when a part brings a hole into a map that had none. */
static void layer_holes(int x0, int y0, int x1, int y1) {
if (!gpu_active() || !layer.hole) return;
+ int any = nlsurf || lsurf_all;
+ if (!any && !layer.has_holes) {
+ for (int y = y0; y < y1; y++) {
+ uint32_t *row = layer.px + (size_t)y * layer.w;
+ for (int x = x0; x < x1; x++) if (row[x] == SENTINEL) row[x] = 0;
+ }
+ return;
+ }
+ int whole = x0 == 0 && y0 == 0 && x1 == layer.w && y1 == layer.h;
+ if (!layer.has_holes && !whole) memset(layer.hole, 0, (size_t)layer.w * layer.h); /* what it stood for */
+ uint8_t set = 0;
for (int y = y0; y < y1; y++) {
uint32_t *row = layer.px + (size_t)y * layer.w;
uint8_t *m = layer.hole + (size_t)y * layer.w;
for (int x = x0; x < x1; x++) {
- m[x] = row[x] == 0 && (nlsurf || lsurf_all) && in_surface(x, y);
+ m[x] = row[x] == 0 && any && in_surface(x, y);
+ set |= m[x];
if (row[x] == SENTINEL) row[x] = 0;
}
}
+ if (whole) layer.has_holes = set;
+ else layer.has_holes |= set;
}
/* Vuelve a anotar las ventanas de apps de la capa (camino GPU) en su lugar de ahora, sin tocar el canvas. */
@@ -744,6 +765,7 @@ static int layer_paint(Canvas *c, Node *n, float opacity) {
/* los huecos de las apps: alfa 0 de verdad (la mezcla no los abre) y la app anotada donde está ahora */
Rect r = c->clip;
int x0 = bx > r.x0 ? bx : r.x0, x1 = bx + layer.w < r.x1 ? bx + layer.w : r.x1;
+ if (layer.has_holes) /* else the map is all 0 */
for (int y = by > r.y0 ? by : r.y0; y < by + layer.h && y < r.y1; y++) {
const uint8_t *m = layer.hole + (size_t)(y - by) * layer.w - bx;
uint32_t *row = c->px + (size_t)y * c->stride;
diff --git a/server/tests/drag_golden_cpu.txt b/server/tests/drag_golden_cpu.txt
index 7067d51..b9ebb9a 100644
--- a/server/tests/drag_golden_cpu.txt
+++ b/server/tests/drag_golden_cpu.txt
@@ -726,3 +726,186 @@ x86_64 edge 57 406eac01704df7ab
x86_64 edge 58 edaa2dd8b5019fd4
x86_64 edge 59 126ee14e877dd553
x86_64 edge 60 6c285a9ccaeb404f
+x86_64 neg 0 6238d1aa9bbf790a
+x86_64 neg 1 2bce21c610ca33c7
+x86_64 neg 2 c998da566b88f664
+x86_64 neg 3 af9eeffdb140b919
+x86_64 neg 4 cdce8195578412fe
+x86_64 neg 5 81015e50a1f643c4
+x86_64 neg 6 9ad98da7a2551e8e
+x86_64 neg 7 5180f32d584b2652
+x86_64 neg 8 748ef6a4ee5611b5
+x86_64 neg 9 5d66a6d9de28dd1b
+x86_64 neg 10 9d30745d9f961f89
+x86_64 neg 11 680496d81a12e362
+x86_64 neg 12 3f1b2b7cb86fbeb4
+x86_64 neg 13 d0fc2a6394e62636
+x86_64 neg 14 0af24e310131730f
+x86_64 neg 15 b49d341b4a3d4fc6
+x86_64 neg 16 f3b3ce5d3e322d8a
+x86_64 neg 17 f42dcb45cda687ba
+x86_64 neg 18 12455535a0927800
+x86_64 neg 19 fef8a5600ee6a8d1
+x86_64 neg 20 c81fc0ddbbc162c4
+x86_64 neg 21 0c32474c48c70fe2
+x86_64 neg 22 47173ecb6cea1664
+x86_64 neg 23 22069ae9bc2303d5
+x86_64 neg 24 aa3f8fd62ad9f966
+x86_64 neg 25 5a19b42488caa50c
+x86_64 neg 26 f49ecc8a86ac85fd
+x86_64 neg 27 d6329505c531527d
+x86_64 neg 28 5fb376881c6a6901
+x86_64 neg 29 fe5538ed095e905d
+x86_64 neg 30 9e6eb47fe99ae29f
+x86_64 neg 31 51c32f62b2c56ada
+x86_64 neg 32 6fd51dd936110206
+x86_64 neg 33 62abd7a1c3af18d8
+x86_64 neg 34 66bd550a10956173
+x86_64 neg 35 aa196ae13a2f70f5
+x86_64 neg 36 48e7e1bd1d7e7b01
+x86_64 neg 37 01a9d045e118d449
+x86_64 neg 38 ebd9f9e1ed17bb98
+x86_64 neg 39 12483e61e7c814b3
+x86_64 neg 40 f4ad9377e429649d
+x86_64 neg 41 8f6a2916ab4ab379
+x86_64 neg 42 bdbc3054e199a93f
+x86_64 neg 43 87343cb5513fd8a7
+x86_64 neg 44 9a246297f08f0ee0
+x86_64 neg 45 26b638609b0b1d60
+x86_64 neg 46 2427867535b3b92d
+x86_64 neg 47 62300ccc008fe1d3
+x86_64 neg 48 ae176e6f2cae85b0
+x86_64 neg 49 c2373131095337b3
+x86_64 neg 50 1f671095642d692a
+x86_64 neg 51 95e520423332fade
+x86_64 neg 52 6ca0cdca94d5d8d5
+x86_64 neg 53 47ea4e828ee83e07
+x86_64 neg 54 20f6f9f4e8839dab
+x86_64 neg 55 e5141e5dd7654c80
+x86_64 neg 56 e7c5920fe6d0a702
+x86_64 neg 57 da2ead543fdfe09b
+x86_64 neg 58 2009429ba36f7d4a
+x86_64 neg 59 d8d2e2a9eafc2a8a
+x86_64 neg 60 2b4c241a021565f5
+x86_64 remove 0 d58c512920b347e8
+x86_64 remove 1 13687938e0106097
+x86_64 remove 2 ea687ac8aba94778
+x86_64 remove 3 47bba3267e7b43b7
+x86_64 remove 4 9376295c84f2e7e8
+x86_64 remove 5 2f7206816233ed18
+x86_64 remove 6 d02ed3ce743e6e2c
+x86_64 remove 7 74faeb22b9ad30ce
+x86_64 remove 8 693578d9d72cd8e2
+x86_64 remove 9 e3d11f296d9073a6
+x86_64 remove 10 8a4f46c42e5f7ac2
+x86_64 remove 11 23208902ed5d1984
+x86_64 remove 12 ac13e68d2fed666e
+x86_64 remove 13 8be99b0231c23b32
+x86_64 remove 14 406301624b347ced
+x86_64 remove 15 3896ff9f34271d03
+x86_64 remove 16 d150085b7ff762b0
+x86_64 remove 17 3ecd508f695d0c18
+x86_64 remove 18 b39e2758b1342631
+x86_64 remove 19 57b1cb039497c811
+x86_64 remove 20 35383fed34bf17b8
+x86_64 remove 21 99b5d57426611f3d
+x86_64 remove 22 246a56e3c6cdb25e
+x86_64 remove 23 8307a3dab9644359
+x86_64 remove 24 9882aacc3666199a
+x86_64 remove 25 814a069a07cb0456
+x86_64 remove 26 8437c8ced62d2f14
+x86_64 remove 27 959bfea3b1d55921
+x86_64 remove 28 658f52ec522fa455
+x86_64 remove 29 9336dc38c9d3454d
+x86_64 remove 30 6f1cc70926980f7c
+x86_64 remove 31 e70b3d0872dbbb6c
+x86_64 remove 32 6030c72e51ee2ee1
+x86_64 remove 33 09c150d56f2dbe69
+x86_64 remove 34 a9f4ac7133955078
+x86_64 remove 35 36160d8b9238ec88
+x86_64 remove 36 ef46625e1812d91a
+x86_64 remove 37 dfed9289f2c6b9f3
+x86_64 remove 38 ba0727a0f08a3f4a
+x86_64 remove 39 66862588ee221695
+x86_64 remove 40 ebf131f817479844
+x86_64 remove 41 475ffab930ef90d8
+x86_64 remove 42 9d952965dd64eca5
+x86_64 remove 43 5a766280f108e91d
+x86_64 remove 44 eada0a61bb374ea1
+x86_64 remove 45 a330db63a84db7cf
+x86_64 remove 46 154f1adbcffb8572
+x86_64 remove 47 957de2543c0d770d
+x86_64 remove 48 45d5765dbadf66d4
+x86_64 remove 49 ba5027a4428b5f5b
+x86_64 remove 50 993e70542f9f6b76
+x86_64 remove 51 be73e416fbfca8da
+x86_64 remove 52 fa221c4e5a5cfbf5
+x86_64 remove 53 d8b98fc3ed550aa3
+x86_64 remove 54 4cba84915994584b
+x86_64 remove 55 1248954140973bce
+x86_64 remove 56 04211e0af86add19
+x86_64 remove 57 0b0990272b3852ad
+x86_64 remove 58 b6be922452b440c9
+x86_64 remove 59 2c43e5687dc8897e
+x86_64 remove 60 4d71fec4ecc62222
+x86_64 k2 0 cf0c25b9be2429d6
+x86_64 k2 1 14d6d432ad64fa09
+x86_64 k2 2 54322d60f8998fcb
+x86_64 k2 3 750d814f76db47dc
+x86_64 k2 4 e0c5f80739daf864
+x86_64 k2 5 0ea92c472403b587
+x86_64 k2 6 c04ddb8704033285
+x86_64 k2 7 5b4a8400d3a865ed
+x86_64 k2 8 5760ecf807205d03
+x86_64 k2 9 8eca06257ab3fd62
+x86_64 k2 10 c1e214d3f955a47f
+x86_64 k2 11 3e9657e74a392936
+x86_64 k2 12 fe29e2ef43fa094b
+x86_64 k2 13 878d51bcc15dff42
+x86_64 k2 14 107228b0c60372e1
+x86_64 k2 15 832f0f29c465540b
+x86_64 k2 16 671ea850ffef8f84
+x86_64 k2 17 bc8cf8ffe5ead2c9
+x86_64 k2 18 bd9831d5cc66f0d7
+x86_64 k2 19 04dd62dc00ef3743
+x86_64 k2 20 2b92e56b9dffa47e
+x86_64 k2 21 8411a7542199bc1e
+x86_64 k2 22 7dbcb5f3e60ff316
+x86_64 k2 23 95520788f24aec6c
+x86_64 k2 24 279c410a938d1ed6
+x86_64 k2 25 174c2e7870f22299
+x86_64 k2 26 b236e3307736d577
+x86_64 k2 27 e6e25fdf38f87c21
+x86_64 k2 28 1bb559d2b265810f
+x86_64 k2 29 6e0a18dbea5e1c46
+x86_64 k2 30 07d221f530e9d0d2
+x86_64 k2 31 12c2171beebebcc2
+x86_64 k2 32 c59f703e22120202
+x86_64 k2 33 58ede2f7495494ab
+x86_64 k2 34 b1a01a7d03c6c6bd
+x86_64 k2 35 ac416a5f87281889
+x86_64 k2 36 dfe3dbe8ba605ee6
+x86_64 k2 37 66fa3ae96d028571
+x86_64 k2 38 60a759f82de1a5b3
+x86_64 k2 39 80888b42ffbcb398
+x86_64 k2 40 7a054bbe2ae26c97
+x86_64 k2 41 559fd72034384cad
+x86_64 k2 42 a75bc7790611061d
+x86_64 k2 43 971c7918c43084f9
+x86_64 k2 44 cf1b159667ef865c
+x86_64 k2 45 e8ecfb48532f3dad
+x86_64 k2 46 9da99915de0d4da9
+x86_64 k2 47 70895d5134de3c01
+x86_64 k2 48 84cf8c1b24039af3
+x86_64 k2 49 1881936ac9a0c790
+x86_64 k2 50 c93ef6b18aaaab8f
+x86_64 k2 51 ee88e3c7faee9066
+x86_64 k2 52 06ed5e25bcbec5f1
+x86_64 k2 53 225fbd02443ee9e4
+x86_64 k2 54 77ecfc788b280ebb
+x86_64 k2 55 0eb1369aa89ac279
+x86_64 k2 56 13dc51f51d67fd12
+x86_64 k2 57 5a079581d878c833
+x86_64 k2 58 469b977bd44478de
+x86_64 k2 59 0f1da0a39e77b12c
+x86_64 k2 60 741b48da27ee8210
diff --git a/server/tests/drag_golden_gpu.txt b/server/tests/drag_golden_gpu.txt
index 1ca053b..3ef8091 100644
--- a/server/tests/drag_golden_gpu.txt
+++ b/server/tests/drag_golden_gpu.txt
@@ -726,3 +726,186 @@ x86_64 edge 57 514a035729871488
x86_64 edge 58 66e640ed2d45bf24
x86_64 edge 59 3ada2bae9396781b
x86_64 edge 60 6c285a9ccaeb404f
+x86_64 neg 0 200885d230f0183e
+x86_64 neg 1 12f47aeddcb20cd3
+x86_64 neg 2 14c67c701d921e9d
+x86_64 neg 3 ca999d2824bc5cdd
+x86_64 neg 4 e6ad60a30ed64b1f
+x86_64 neg 5 2a1444766263a9d1
+x86_64 neg 6 1358f44ccda32f3d
+x86_64 neg 7 cccfd0a52d01f893
+x86_64 neg 8 4dfb0c55ebd15290
+x86_64 neg 9 f35de2ef5d3e6060
+x86_64 neg 10 404b25b48490fcbb
+x86_64 neg 11 e5d2ac2e599a5087
+x86_64 neg 12 8dc86b48492cdb2d
+x86_64 neg 13 26824b056444c227
+x86_64 neg 14 12eab201293e9030
+x86_64 neg 15 c5e207a3ff5c8ee2
+x86_64 neg 16 8a7ed5e185fe12a5
+x86_64 neg 17 1c147c4531fd420c
+x86_64 neg 18 a2f518914abe70ee
+x86_64 neg 19 54fa6abf2f098af8
+x86_64 neg 20 0e178ccb96a87095
+x86_64 neg 21 307b18efa3d432ca
+x86_64 neg 22 616cc0b5360b0414
+x86_64 neg 23 a0ce217d20b1ac6a
+x86_64 neg 24 13b2f4c00b19e13d
+x86_64 neg 25 8b6df053baa89df5
+x86_64 neg 26 9832f463806504a3
+x86_64 neg 27 5d3570699d8135c8
+x86_64 neg 28 dba40a62095b0bbb
+x86_64 neg 29 77388106cbe69405
+x86_64 neg 30 f3bfd55668c349f5
+x86_64 neg 31 0d6227bdbcab4644
+x86_64 neg 32 351f067d75b8f50f
+x86_64 neg 33 895b20d927f858af
+x86_64 neg 34 dcdd19799acbd7c5
+x86_64 neg 35 f6bb4f46b09658c7
+x86_64 neg 36 e076363f677b410b
+x86_64 neg 37 8037776e0048ba51
+x86_64 neg 38 d3218db983035c58
+x86_64 neg 39 c7a92dc658217245
+x86_64 neg 40 4fa2452bb8044537
+x86_64 neg 41 56ada52c5d97312e
+x86_64 neg 42 3e4c4d9046dc9673
+x86_64 neg 43 a31c70a9fc34d823
+x86_64 neg 44 4636b4b494d39fff
+x86_64 neg 45 a7a71880da46614e
+x86_64 neg 46 9e8274d88f4bf415
+x86_64 neg 47 9fe5a5aea0945ae8
+x86_64 neg 48 908fe6fb40701fd3
+x86_64 neg 49 34cf3770a94a9123
+x86_64 neg 50 5a7cf234d69fc243
+x86_64 neg 51 e4384863a4b5243f
+x86_64 neg 52 ef2e8b27330addfb
+x86_64 neg 53 50ee3622ce25e62e
+x86_64 neg 54 573033e72f299f94
+x86_64 neg 55 2404ce01aef48760
+x86_64 neg 56 0375a004b7187edf
+x86_64 neg 57 d007bb03cb2ef395
+x86_64 neg 58 3780c605b1437421
+x86_64 neg 59 3c7aa98662e2c353
+x86_64 neg 60 2b4c241a021565f5
+x86_64 remove 0 d58c512920b347e8
+x86_64 remove 1 9992f5dee0632cef
+x86_64 remove 2 c422be5ea82c7783
+x86_64 remove 3 bbe1e605cc6663e5
+x86_64 remove 4 1fcc5196bc0184c5
+x86_64 remove 5 2af552af382fa9df
+x86_64 remove 6 ba43b39412e16e6f
+x86_64 remove 7 32eea4d5aea31aa4
+x86_64 remove 8 81398cf57d8f8f8a
+x86_64 remove 9 9e730fbae9b353d4
+x86_64 remove 10 e8cd2340138e4b7d
+x86_64 remove 11 89e0b9c33e16c9a3
+x86_64 remove 12 d93b52e4e86b3950
+x86_64 remove 13 6020bd40644d10d2
+x86_64 remove 14 8a5af718bec2a0b6
+x86_64 remove 15 2800c6fff44a845b
+x86_64 remove 16 5b047f1b9b94d47d
+x86_64 remove 17 1e372c8a1fc83d3b
+x86_64 remove 18 d4a2a380ac0dde98
+x86_64 remove 19 3202f32332c5fa07
+x86_64 remove 20 e25ba8269074e5cd
+x86_64 remove 21 db04e01210fb4361
+x86_64 remove 22 e2397e328a5f00bf
+x86_64 remove 23 6f8762314af7e603
+x86_64 remove 24 4b34038172bed3d5
+x86_64 remove 25 c1a964053666d5a2
+x86_64 remove 26 fb858c4604504345
+x86_64 remove 27 aba7d4fe5fdc64f5
+x86_64 remove 28 228ef710a1cb083f
+x86_64 remove 29 3e4025b32e674c6c
+x86_64 remove 30 96fa1c932db2e6ef
+x86_64 remove 31 a09d71a06260e78e
+x86_64 remove 32 9ebb7a9da7f4f4a7
+x86_64 remove 33 ff25f26fdc250067
+x86_64 remove 34 f5bf8dd25686aff9
+x86_64 remove 35 5bd988f5b4f23417
+x86_64 remove 36 6467c779fcca25ff
+x86_64 remove 37 ca8d1efeb9a51aab
+x86_64 remove 38 fac8abc8f0fb01f5
+x86_64 remove 39 7d8cb64a5103767c
+x86_64 remove 40 9377969057c7e107
+x86_64 remove 41 58067e6975816647
+x86_64 remove 42 51311c659f963b4d
+x86_64 remove 43 839603c9bd2cb5d5
+x86_64 remove 44 c16a563881808f8b
+x86_64 remove 45 0e299527a8b21ddb
+x86_64 remove 46 be7d2f1bc471ddc6
+x86_64 remove 47 528a894d46294803
+x86_64 remove 48 ed797a2cbc12a800
+x86_64 remove 49 67044028aa025856
+x86_64 remove 50 626b5bf6b36d136c
+x86_64 remove 51 265711800acbc6f8
+x86_64 remove 52 0d7c6b6348cc9399
+x86_64 remove 53 95eed3803825365a
+x86_64 remove 54 7be5e50dd0c43b5e
+x86_64 remove 55 694af18420de4bfe
+x86_64 remove 56 7e4074a5c36a528f
+x86_64 remove 57 318e4bfecdf0574a
+x86_64 remove 58 4145ace265df1d81
+x86_64 remove 59 ccf07a58aa4f6022
+x86_64 remove 60 4d71fec4ecc62222
+x86_64 k2 0 cf0c25b9be2429d6
+x86_64 k2 1 db4e7470876186f1
+x86_64 k2 2 31427d7011223827
+x86_64 k2 3 5e66dc3ccb56ce7e
+x86_64 k2 4 48a5b7019b9679c4
+x86_64 k2 5 806a43ffe5404925
+x86_64 k2 6 25262930afe12529
+x86_64 k2 7 e7789b424054a3a5
+x86_64 k2 8 185ffa7369d5756b
+x86_64 k2 9 f3de92eaa96f8685
+x86_64 k2 10 b663bf7d2c6f6dbf
+x86_64 k2 11 5b2fedcb981bf148
+x86_64 k2 12 42f57afd2c25c4e4
+x86_64 k2 13 e9afe28d4d29ff17
+x86_64 k2 14 dae286c0d06b11a0
+x86_64 k2 15 b1758a9ea29cab0e
+x86_64 k2 16 c5248edcc8c64fdc
+x86_64 k2 17 67d9a86bbc5a3435
+x86_64 k2 18 2e8a87869ddd94e7
+x86_64 k2 19 b9d4efd5242246a6
+x86_64 k2 20 ba115cde39fdf829
+x86_64 k2 21 72a41b549e555b24
+x86_64 k2 22 cd4313a6cb775749
+x86_64 k2 23 ae07dc8fe70b4782
+x86_64 k2 24 bdcad8155f4eeec9
+x86_64 k2 25 e22ad8c5814f7093
+x86_64 k2 26 28e42c347a5b4a55
+x86_64 k2 27 f3cb403d54a1656a
+x86_64 k2 28 d17ab52a4578f28e
+x86_64 k2 29 03086260f86d803d
+x86_64 k2 30 8d00fb3716c84c75
+x86_64 k2 31 8751f70105146b4a
+x86_64 k2 32 239f991507c31d85
+x86_64 k2 33 2f4f33eb0a988b1a
+x86_64 k2 34 a311aa1ca2b2dd26
+x86_64 k2 35 0b69ebd960ae5f3c
+x86_64 k2 36 06f75f77ba83a3eb
+x86_64 k2 37 64d78f5109e733e4
+x86_64 k2 38 64a5b72a31fe7292
+x86_64 k2 39 31487ab3b4caee46
+x86_64 k2 40 100aebbb85b016e0
+x86_64 k2 41 34d2138719d7cba1
+x86_64 k2 42 f44adc2c3f8a52bf
+x86_64 k2 43 01082eb89cf40990
+x86_64 k2 44 bdfb959b6449b3cb
+x86_64 k2 45 f007bd83a8c9ee24
+x86_64 k2 46 4fee362e6ae10487
+x86_64 k2 47 8612af26025a21b8
+x86_64 k2 48 b13c7865e61e64b0
+x86_64 k2 49 db97638eda1a00db
+x86_64 k2 50 ae08afb7a05b7f66
+x86_64 k2 51 6a5595c26018bda4
+x86_64 k2 52 4bc989450963b0df
+x86_64 k2 53 4a779e4fde301ef2
+x86_64 k2 54 d0da120b78c57cc1
+x86_64 k2 55 70db746f43261789
+x86_64 k2 56 1c3daafa2a4e50a4
+x86_64 k2 57 f8d980a047796ca5
+x86_64 k2 58 c72f32aacf5ca23b
+x86_64 k2 59 a742b2ecf6b27cb5
+x86_64 k2 60 741b48da27ee8210
diff --git a/server/tests/engine_test.c b/server/tests/engine_test.c
index 110a064..ba10d3e 100644
--- a/server/tests/engine_test.c
+++ b/server/tests/engine_test.c
@@ -1442,16 +1442,17 @@ static void test_overlay_scrollbar(void) {
* it, six cards with shadows and text; a rounded window below; a menu bar and a Dock with backdrop
* blur) moved along LordBench's figure of eight (lbi_path, one step a frame as grab_script_tick does
* by the clock) for 480 frames, the square turning 6° a frame through lord.setStyle's C path
- * (node_restyled; with 'rotate', what runtime/style.js makes of a transform: scene.jsx's own
- * setStyle(n, 'transform', …) is not a key lord.setStyle takes), and painted as main.c paints a frame
+ * (node_restyled with 'rotate', as scene.jsx sends it), and painted as main.c paints a frame
* (paint_ui, then paint_out on one display).
* Every frame's pixels are hashed (FNV-1a over the 32-bit pixels) and compared with
* tests/drag_golden_cpu.txt and tests/drag_golden_gpu.txt, written from the code before the drag-frame
* optimizations (001633b): those must give exactly the same pixels. "gpu" is the same run with
* gpu_active() on: paint.c's GPU path (the layer's sentinel, the app holes, no skipped nodes) on the
- * same CPU canvas the GPU uploads. Four shorter runs cover what makes the layer paint again: a text
+ * same CPU canvas the GPU uploads. Shorter runs cover what makes the layer paint again: a text
* that changes a child's size, a child moving inside the window, a terminal whose cursor blinks
- * (damage from outside the tree) and a square turning across the window's edge.
+ * (damage from outside the tree), a square turning across the window's edge, the window crossing
+ * x = 0 and y = 0 while the square turns, a child removed after frames that only copy the layer and
+ * then the square turning again, and the whole drag on a display at 200 %.
* The pixels that differ from a full repaint (paint_root_full, as LORD_PAINT_VERIFY) are printed as a
* second number, which may only go down (today: black pixels at the dragged window's own rounded top
* corners on the CPU path, its shadow one level darker on the GPU path).
@@ -1466,10 +1467,11 @@ static void test_overlay_scrollbar(void) {
#endif
enum { DW = 1024, DH = 640, DRAG_FRAMES = 480, CASE_FRAMES = 60, FULL_EVERY = 16 };
-enum { DC_DRAG, DC_TEXT, DC_CHILD, DC_TERM, DC_EDGE, DC_N };
-static const char *const dc_name[DC_N] = { "drag", "text", "child", "term", "edge" };
-static const int dc_frames[DC_N] = { DRAG_FRAMES, CASE_FRAMES, CASE_FRAMES, CASE_FRAMES, CASE_FRAMES };
-#define DC_HASHES (DRAG_FRAMES + 4 * CASE_FRAMES + DC_N) /* each run: its frames and the one after the drag */
+enum { DC_DRAG, DC_TEXT, DC_CHILD, DC_TERM, DC_EDGE, DC_NEG, DC_REMOVE, DC_K2, DC_N };
+static const char *const dc_name[DC_N] = { "drag", "text", "child", "term", "edge", "neg", "remove", "k2" };
+static const int dc_frames[DC_N] = { DRAG_FRAMES, CASE_FRAMES, CASE_FRAMES, CASE_FRAMES, CASE_FRAMES,
+ CASE_FRAMES, CASE_FRAMES, CASE_FRAMES };
+#define DC_HASHES (DRAG_FRAMES + (DC_N - 1) * CASE_FRAMES + DC_N) /* each run: its frames and the one after the drag */
typedef struct { OutView v; Canvas c, ref; uint32_t *px, *rpx; } DOut;
typedef struct { Node *root, *win, *spin, *edge, *child, *term, *caption; } DScene;
@@ -1620,10 +1622,23 @@ static DScene drag_scene(int dc, float x, float y) {
Node *cap = dtext(c, label, 12, 0, 0x99ffffff);
if (!i) s.caption = cap;
}
- if (dc == DC_CHILD) { /* a badge that slides inside the window */
+ if (dc == DC_CHILD || dc == DC_REMOVE) { /* a badge that slides inside the window, or is removed */
s.child = box_in(s.win, 40, 44, 14, 14, 0xffff453a);
sn(s.child, "borderRadius", 7);
}
+ if (dc == DC_NEG || dc == DC_REMOVE || dc == DC_K2) {
+ /* odd widths centered in a column: boxes, shadows and text at half pixels, which a move by
+ * whole pixels must not round differently (across x = 0, at 200 %) */
+ Node *col = box_in(s.win, 24, 40, 210, 200, 0);
+ ss(col, "alignItems", "center");
+ sn(col, "gap", 7);
+ for (int i = 0; i < 4; i++) {
+ Node *c = dview(col, 101 + 2 * i, 31, 0x22ffffff, 6);
+ ss(c, "alignItems", "center"); ss(c, "justifyContent", "center");
+ dshadow(c, 0x50000000, 2, 7);
+ dtext(c, i & 1 ? "fig iq Wj 1.5" : "Half pixel label", 13, 0, 0xffffffff);
+ }
+ }
if (dc == DC_TERM) { /* a terminal, its cursor blinking */
s.term = node_new(NODE_TERM);
s.term->term = 1;
@@ -1654,13 +1669,14 @@ static DScene drag_scene(int dc, float x, float y) {
return s;
}
-/* One run: case dc's scene, the drag (n frames), then the frame after it ends. hash gets n + 1
- * values; the largest count of pixels that differed from a full repaint goes to *full, the largest
- * difference of a channel to *worst. */
+/* One run: case dc's scene, the drag (n frames), then the frame after it ends, on o (a display at
+ * 100 %, or at 200 % for DC_K2). hash gets n + 1 values; the largest count of pixels that differed
+ * from a full repaint goes to *full, the largest difference of a channel to *worst. */
static void drag_run(int dc, DOut *o, uint64_t *hash, long *full, int *worst) {
const int n = dc_frames[dc];
- const float x0 = (DW - 760) / 2, y0 = 28 + (DH - 28 - 480) / 2; /* scenePath: centered in the work area */
+ float x0 = (DW - 760) / 2, y0 = 28 + (DH - 28 - 480) / 2; /* scenePath: centered in the work area */
const float rx = (DW - 760) / 2 - 20, ry = (DH - 28 - 480) - 40;
+ if (dc == DC_NEG) { x0 = -200; y0 = -120; } /* partly off the display's top-left corner */
DScene s = drag_scene(dc, x0, y0);
term_cursor = 1;
term_at = (Box){ 0, 0, 0, 0 };
@@ -1676,6 +1692,7 @@ static void drag_run(int dc, DOut *o, uint64_t *hash, long *full, int *worst) {
for (int f = 0; f < n; f++) {
float dx, dy;
lbi_path(rx, ry, 6000, f * (1000.0 / 60), &dx, &dy);
+ if (dc == DC_NEG) { dx = 6 * f; dy = 4 * f; } /* its left edge crosses x = 0, its top y = 0 */
float x = x0 + roundf(dx), y = y0 + roundf(dy); /* grab_motion */
if (x != gx || y != gy) {
gx = x; gy = y;
@@ -1685,7 +1702,9 @@ static void drag_run(int dc, DOut *o, uint64_t *hash, long *full, int *worst) {
ui.dirty = 1;
}
rot = fmodf(rot + 6, 360); /* scene.jsx's square, every 16 ms */
- if (dc == DC_DRAG) js_set(s.spin, "rotate", rot); /* the others: only their own change */
+ if (dc == DC_DRAG || dc == DC_NEG || dc == DC_K2) js_set(s.spin, "rotate", rot); /* the others: their own */
+ if (dc == DC_REMOVE && f % 10 == 0) js_set(s.spin, "rotate", rot); /* frames between only copy the layer */
+ if (dc == DC_REMOVE && f == 35) node_detach(s.child);
if (dc == DC_EDGE) js_set(s.edge, "rotate", rot);
if (dc == DC_CHILD) js_set(s.child, "left", 40 + (f * 5) % 640);
if (dc == DC_TEXT && f % 15 == 7) /* lord.setText on the caption: one line or two */
@@ -1763,14 +1782,23 @@ static int gold_write(const char *path, const char *variant, const uint64_t *has
static void test_drag_exact(int write) {
static const char *const variant[2] = { "cpu", "gpu" };
- DOut o = { 0 };
+ DOut o = { 0 }, o2 = { 0 }; /* the display at 100 %, and at 200 % (DC_K2) */
o.v = out_view(0, 0, DW, DH, 100);
+ o2.v = out_view(0, 0, 2 * DW, 2 * DH, 200);
o.px = calloc((size_t)DW * DH, 4);
o.rpx = calloc((size_t)DW * DH, 4);
+ o2.px = calloc((size_t)4 * DW * DH, 4);
+ o2.rpx = calloc((size_t)4 * DW * DH, 4);
uint64_t *hash = malloc(sizeof *hash * DC_HASHES);
- if (!o.px || !o.rpx || !hash) { CHECK(0, "drag-exact: out of memory"); free(o.px); free(o.rpx); free(hash); return; }
+ if (!o.px || !o.rpx || !o2.px || !o2.rpx || !hash) {
+ CHECK(0, "drag-exact: out of memory");
+ free(o.px); free(o.rpx); free(o2.px); free(o2.rpx); free(hash);
+ return;
+ }
canvas_init(&o.c, o.px, DW, DH, DW);
canvas_init(&o.ref, o.rpx, DW, DH, DW);
+ canvas_init(&o2.c, o2.px, 2 * DW, 2 * DH, 2 * DW);
+ canvas_init(&o2.ref, o2.rpx, 2 * DW, 2 * DH, 2 * DW);
for (int g = 0; g < 2; g++) {
test_gpu = g;
char path[64];
@@ -1782,7 +1810,7 @@ static void test_drag_exact(int write) {
paint_layer_parts();
paint_layer_stats(&renders, &blits);
for (int dc = 0; dc < DC_N; dc++) {
- drag_run(dc, &o, hash + k, &fullw[dc], &worst[dc]);
+ drag_run(dc, dc == DC_K2 ? &o2 : &o, hash + k, &fullw[dc], &worst[dc]);
k += dc_frames[dc] + 1;
}
parts = paint_layer_parts();
@@ -1818,9 +1846,142 @@ static void test_drag_exact(int write) {
test_gpu = 0;
free(o.px);
free(o.rpx);
+ free(o2.px);
+ free(o2.rpx);
free(hash);
}
+/* ---- A setStyle that only turns or scales a node (node_restyled's transform-only path) ----
+ * Two copies of one tree: A takes rotate/scaleX/scaleY/transformOriginX through node_restyled (which
+ * keeps the node's own layout and every measure when that gives the same results), B through what
+ * node_restyled did before (node_invalidate on any change). Between the turns, both get the same
+ * other changes (a width that moves by fractions of a pixel, a font size, the root's size), so text
+ * measured within its half-pixel cache is in play. Every node must lay out exactly the same (box,
+ * absolute position, matrices, text measure) and both trees must paint the same pixels. 'transform'
+ * itself (apps/sysinfo/scene.jsx, sdk/cooling.jsx) is no key lord.setStyle takes: it changes nothing. */
+typedef struct { Node *root, *col, *label, *spin[5]; } TScene;
+
+static TScene tr_scene(void) {
+ TScene t;
+ t.root = view(NULL);
+ sn(t.root, "backgroundColor", 0xfff2f2f7);
+ ss(t.root, "flexDirection", "row"); ss(t.root, "flexWrap", "wrap");
+ t.col = dview(t.root, 180, 0, 0xffffffff, 8);
+ t.label = dtext(t.col, "A label that wraps over more than one line of this column", 13, 0, 0xff202020);
+ t.spin[0] = dview(t.col, 40, 40, 0xff0a84ff, 10); /* a leaf */
+ t.spin[1] = dview(t.root, 72, 72, 0xff34c759, 16); /* with a box inside */
+ ss(t.spin[1], "alignItems", "center"); ss(t.spin[1], "justifyContent", "center");
+ dview(t.spin[1], 24, 24, 0xffffffff, 12);
+ Node *abs = dview(t.spin[1], 10, 10, 0xffff9500, 0);
+ ss(abs, "position", "absolute"); sn(abs, "left", 2); sn(abs, "top", 3);
+ t.spin[2] = dview(t.root, 0, 0, 0xffff3b30, 6); /* with text inside: invalidated */
+ sn(t.spin[2], "paddingLeft", 4); sn(t.spin[2], "paddingRight", 4); sn(t.spin[2], "paddingTop", 2);
+ dtext(t.spin[2], "Turning words", 12, 600, 0xffffffff);
+ Node *tt = dtext(t.root, "Text around ", 14, 0, 0xff000000); /* a box under a text node */
+ t.spin[3] = dview(tt, 12, 12, 0xff5856d6, 0);
+ t.spin[4] = dview(t.root, 0, 30, 0xffaf52de, 4); /* sized by flex */
+ sn(t.spin[4], "flexGrow", 1);
+ return t;
+}
+
+static int tr_same(const Node *a, const Node *b, int *bad) {
+ int n = 1;
+ if (a->type != b->type || a->x != b->x || a->y != b->y || a->w != b->w || a->h != b->h || a->ax != b->ax ||
+ a->ay != b->ay || a->own_tf != b->own_tf || a->has_tf != b->has_tf ||
+ (a->type == NODE_TEXT && (a->measure_w != b->measure_w || a->measure_h != b->measure_h)) ||
+ (a->has_tf && (memcmp(&a->tf->own, &b->tf->own, sizeof a->tf->own) || memcmp(&a->tf->world, &b->tf->world, sizeof a->tf->world) ||
+ memcmp(&a->tf->inv, &b->tf->inv, sizeof a->tf->inv)))) (*bad)++;
+ const Node *ca = a->first, *cb = b->first;
+ for (; ca && cb; ca = ca->next, cb = cb->next) n += tr_same(ca, cb, bad);
+ if (ca || cb) (*bad)++;
+ return n;
+}
+
+/* what node_restyled did with a changed transform before the fast path */
+static void tr_set_old(Node *n, const char *k, double v) {
+ Style before = n->s;
+ StyleExt xb;
+ if (n->s.ext) memcpy(&xb, n->s.ext, STYLE_EXT_VALUES);
+ style_set_number(&n->s, k, v);
+ if (memcmp(&before, &n->s, sizeof before) || !before.ext || memcmp(&xb, n->s.ext, STYLE_EXT_VALUES)) node_invalidate(n);
+}
+
+static void test_transform_restyle(void) {
+ ui_reset();
+ TScene a = tr_scene(), b = tr_scene();
+ enum { TW = 420, TH = 300 };
+ uint32_t *pa = calloc((size_t)TW * TH, 4), *pb = calloc((size_t)TW * TH, 4);
+ Canvas ca, cb;
+ canvas_init(&ca, pa, TW, TH, TW);
+ canvas_init(&cb, pb, TW, TH, TW);
+ long bad = 0, nodes = 0, pxbad = 0;
+ int fast = 0, slow = 0;
+ const char *const key[] = { "rotate", "scaleX", "scaleY", "transformOriginX", "transformOriginY" };
+ for (int f = 0; f < 120; f++) {
+ if (f % 7 == 3) { sn(a.col, "width", 180 + (f % 5) * 0.3); sn(b.col, "width", 180 + (f % 5) * 0.3); }
+ if (f % 11 == 5) { sn(a.label, "fontSize", 13 + (f % 3)); sn(b.label, "fontSize", 13 + (f % 3)); }
+ for (int i = 0; i < 5; i++) {
+ const char *k = key[f % 9 < 5 ? 0 : (f % 9 - 4)];
+ double v = k == key[0] ? f * 7 + i * 13 : k == key[3] || k == key[4] ? 4 + (f % 5) * 2.5 : 0.55 + (f % 4) * 0.125;
+ Node *n = a.spin[i];
+ int had = n->s.ext != NULL, lok = n->layout_ok;
+ ui.dirty = 0;
+ js_set(n, k, v);
+ tr_set_old(b.spin[i], k, v);
+ if (had && lok && i != 2 && i != 3) {
+ fast += n->layout_ok;
+ CHECK(ui.dirty && n->paint_dirty && !n->parent->layout_ok, "transform-only change not repainted or placed");
+ }
+ if (i == 2 || i == 3) { slow++; CHECK(!n->layout_ok, "node %d: laid out from its cache with text in the way", i); }
+ }
+ float w = TW - (f % 4) * 0.2f, h = TH;
+ layout_root(a.root, w, h);
+ layout_root(b.root, w, h);
+ int nb = 0;
+ nodes += tr_same(a.root, b.root, &nb);
+ bad += nb;
+ paint_damage(a.root);
+ paint_damage(b.root);
+ ui.damage = (Box){ 0, 0, 0, 0 };
+ canvas_clear(&ca, 0);
+ canvas_clear(&cb, 0);
+ paint_root_full(&ca, a.root);
+ paint_root_full(&cb, b.root);
+ for (size_t i = 0; i < (size_t)TW * TH; i++) pxbad += pa[i] != pb[i];
+ }
+ CHECK(bad == 0, "transform-only setStyle: %ld of %ld node layouts differ", bad, nodes);
+ CHECK(pxbad == 0, "transform-only setStyle: %ld pixels differ", pxbad);
+ CHECK(fast > 300, "the transform-only path was not taken (%d)", fast);
+ CHECK(slow == 240, "text cases: %d", slow);
+
+ /* 'transform' (not a key): nothing set, nothing marked */
+ Node *n = a.spin[0];
+ layout_root(a.root, TW, TH);
+ paint_damage(a.root);
+ ui.damage = (Box){ 0, 0, 0, 0 };
+ ui.dirty = 0;
+ Style before = n->s;
+ StyleExt xb;
+ memcpy(&xb, n->s.ext, STYLE_EXT_VALUES);
+ int lok = n->layout_ok, plok = n->parent->layout_ok;
+ CHECK(style_set_string(&n->s, "transform", "rotate(30deg)") != 0, "'transform' became a style key");
+ node_restyled(n, &before, &xb);
+ CHECK(!ui.dirty && !n->paint_dirty && n->layout_ok == lok && n->parent->layout_ok == plok &&
+ !memcmp(&before, &n->s, sizeof before) && !memcmp(&xb, n->s.ext, STYLE_EXT_VALUES),
+ "setStyle 'transform' changed something");
+ Node *bare = dview(a.root, 10, 10, 0xff000000, 0); /* no StyleExt yet */
+ layout_root(a.root, TW, TH);
+ paint_damage(a.root);
+ ui.dirty = 0;
+ before = bare->s;
+ style_set_string(&bare->s, "transform", "scale(2)");
+ node_restyled(bare, &before, NULL);
+ CHECK(!ui.dirty && !bare->paint_dirty && !bare->s.ext, "setStyle 'transform' on a plain node changed something");
+ ui.damage = (Box){ 0, 0, 0, 0 };
+ free(pa);
+ free(pb);
+}
+
#endif
/* ---- benchmark: a Files-like list and a window drag (docs/DESIGN.md, Engine notes) ---- */
@@ -2025,6 +2186,7 @@ int main(int argc, char **argv) {
test_damage_fuzz();
test_grow_wrap_height();
test_overlay_scrollbar();
+ test_transform_restyle();
printf("engine-test: %d checks, %d failures\n", checks, fails);
return fails ? 1 : 0;
#endif
diff --git a/server/tests/run_suites.sh b/server/tests/run_suites.sh
index 7248429..6581d4a 100644
--- a/server/tests/run_suites.sh
+++ b/server/tests/run_suites.sh
@@ -180,6 +180,10 @@ EOF
# (0.8.5) Settings → Displays' arrangement (sdk/displaylayout.js): numbers, magnetic snap, valid drops
if have node; then run "display-layout-test (sdk/displaylayout.js)" node tests/display_layout_test.mjs
else skip "display-layout-test" "node"; fi
+ # (0.8.6) runtime/index.js's skip of unchanged styles sends the same lord.* calls as without it
+ if have node && [ -d ../node_modules/esbuild ] && [ -d ../node_modules/react-reconciler ]; then
+ run "runtime-props-test (runtime/index.js)" node tests/runtime_props_test.mjs
+ else skip "runtime-props-test" "node and the repository's node_modules (npm install)"; fi
}
full() {
diff --git a/server/tests/runtime_props_scene.mjs b/server/tests/runtime_props_scene.mjs
new file mode 100644
index 0000000..d23eac1
--- /dev/null
+++ b/server/tests/runtime_props_scene.mjs
@@ -0,0 +1,103 @@
+// runtime_props_scene.mjs — the scene of tests/runtime_props_test.mjs (not run by itself): fuzzed React
+// trees rendered through runtime/index.js with a recording `lord` (the mock comes in as the bundle's
+// banner, so it exists before the runtime loads). Prints every native call, then each node's final
+// style. Usage, after the test bundles it: node <bundle> SEED STEPS
+import React from 'react';
+import * as rt from '@lordos/runtime';
+
+const { log, fmt, state } = globalThis.__lordTest;
+const seed0 = +(process.argv[2] || 1), STEPS = +(process.argv[3] || 300);
+const h = React.createElement;
+
+// xorshift32, so both bundles see the same trees
+let rnd = seed0 >>> 0 || 1;
+const r = () => { rnd ^= rnd << 13; rnd >>>= 0; rnd ^= rnd >>> 17; rnd ^= rnd << 5; rnd >>>= 0; return rnd / 4294967296; };
+const pick = (a) => a[Math.floor(r() * a.length)];
+// values that normalize expands, overrides (margin / marginTop), NaN ('#zz', a gradient without an
+// angle, NaN itself), -0, the values normalize drops (undefined, null, false) and objects (transform)
+const VALUES = {
+ width: [10, 20, '50%', 'auto', '12px', NaN, -0, 0, undefined],
+ height: [10, 30, '100%', null, false],
+ backgroundColor: ['#fff', '#zz', 'red', 'rgba(0,0,0,.5)', 0xff00ff00, '#12345678', undefined],
+ color: ['#000', 'white', 'rgb(1 2 3)', '#abc'],
+ margin: [0, 4, '4px 8px', '1 2 3', '1 2 3 4'],
+ marginTop: [0, 8, -0, '3px'],
+ padding: [2, '2px 4px'],
+ flex: [1, 0, -1, '2'],
+ borderRadius: [4, 8, '6px'],
+ boxShadow: ['0 2px 8px rgba(0,0,0,.3)', 'none', '0 24px 56px #000'],
+ background: ['linear-gradient(to right, red, blue)', 'linear-gradient(deg, red, blue)', 'linear-gradient(45deg, #fff, #000)', '#333'],
+ transform: [[{ rotate: '45deg' }], [{ scale: 2 }, { translateX: 3 }], 'rotate(0.5turn)', 'none'],
+ transformOrigin: ['center', 'top left', '10px 20%'],
+ fontWeight: [400, 'bold', 'semibold', '700'],
+ fontFamily: ['mono', 'Inter', 'brand'],
+ opacity: [1, 0.5, '0.25', NaN],
+ display: ['flex', 'none'],
+ textAlign: ['start', 'end'],
+ border: ['1px solid #ccc', '2 solid red'],
+ marginInline: ['4 8', 3],
+ lineClamp: [1, 2],
+ zIndex: [1, 2, 3],
+};
+const KEYS = Object.keys(VALUES);
+function randStyle() {
+ const o = {};
+ const n = Math.floor(r() * 6);
+ for (let i = 0; i < n; i++) { const k = pick(KEYS); o[k] = pick(VALUES[k]); }
+ return o;
+}
+function shuffled(o) {
+ const ks = Object.keys(o);
+ for (let i = ks.length - 1; i > 0; i--) { const j = Math.floor(r() * (i + 1)); [ks[i], ks[j]] = [ks[j], ks[i]]; }
+ const out = {};
+ for (const k of ks) out[k] = o[k];
+ return out;
+}
+// The style a node gets on the next render, from its previous one: a new random style, the same object,
+// an equal copy, the same object changed in place (a key set or deleted), the same values in another
+// order, a copy with one key changed, or one key set to undefined.
+function evolve(prev) {
+ const x = r();
+ if (prev === undefined || x < 0.08) return r() < 0.3 ? [randStyle(), r() < 0.5 && randStyle(), null] : randStyle();
+ if (x < 0.35) return prev; // same object
+ if (x < 0.65) return Array.isArray(prev) ? prev.map((s) => (s ? { ...s } : s)) : { ...prev }; // equal copy
+ if (x < 0.72) { if (!Array.isArray(prev)) { const k = pick(KEYS); prev[k] = pick(VALUES[k]); } return prev; } // changed in place
+ if (x < 0.76) { if (!Array.isArray(prev)) { const k = pick(KEYS); delete prev[k]; } return prev; }
+ if (x < 0.84) return Array.isArray(prev) ? prev : shuffled(prev); // same values, other order
+ if (x < 0.92) { const c = Array.isArray(prev) ? [...prev] : { ...prev }; if (!Array.isArray(c)) { const k = pick(KEYS); c[k] = pick(VALUES[k]); } return c; }
+ return Array.isArray(prev) ? prev.map((s) => (s ? { ...s } : s)) : { ...prev, [pick(KEYS)]: undefined };
+}
+
+const N = 24;
+let styles = [], texts = [], hidden = false, srcs = [], prot = [], order = [];
+for (let i = 0; i < N; i++) { styles[i] = evolve(undefined); texts[i] = 't' + i; srcs[i] = undefined; prot[i] = false; order[i] = i; }
+let bump = null;
+function Tree() {
+ const [, set] = React.useState(0);
+ bump = () => set((x) => x + 1);
+ const kids = order.map((i) => h(i % 5 === 4 ? rt.Image : i % 3 === 0 ? rt.Text : rt.View,
+ { key: i, style: styles[i], src: i % 5 === 4 ? srcs[i] : undefined, protected: prot[i] }, i % 3 === 0 ? texts[i] : null));
+ const inner = h(rt.View, { style: styles[0] }, kids.slice(0, N / 2));
+ const act = React.Activity ? h(React.Activity, { mode: hidden ? 'hidden' : 'visible' }, h(rt.View, { style: styles[1] }, kids.slice(N / 2))) : kids.slice(N / 2);
+ return h(rt.View, { style: { flex: 1 } }, inner, act);
+}
+// React schedules with setImmediate in node: let every update commit
+const flush = async () => { for (let i = 0; i < 20; i++) await new Promise((res) => setImmediate(res)); };
+rt.render(h(Tree));
+await flush();
+for (let step = 0; step < STEPS; step++) {
+ for (let i = 0; i < N; i++) {
+ styles[i] = evolve(styles[i]);
+ if (r() < 0.1) texts[i] = 't' + Math.floor(r() * 4);
+ if (r() < 0.05) srcs[i] = pick([undefined, 'a.png', 'b.png']);
+ if (r() < 0.03) prot[i] = !prot[i];
+ }
+ if (r() < 0.05) hidden = !hidden;
+ if (r() < 0.05) order = order.slice().sort(() => r() - 0.5);
+ if (r() < 0.03) order = order.filter((x) => x !== pick(order));
+ bump();
+ await flush();
+ log.push(`-- step ${step}`);
+}
+for (const [id, s] of state) log.push(`final ${id} ${Object.keys(s).sort().map((k) => k + '=' + fmt(s[k])).join(' ')}`);
+process.stdout.write(log.join('\n') + '\n');
diff --git a/server/tests/runtime_props_test.mjs b/server/tests/runtime_props_test.mjs
new file mode 100644
index 0000000..42ad45d
--- /dev/null
+++ b/server/tests/runtime_props_test.mjs
@@ -0,0 +1,102 @@
+// runtime_props_test.mjs — (0.8.6) applyProps in runtime/index.js skips normalize and applyStyle when a
+// node's flattened style is the same as last time (same keys, same order, same primitive values). This
+// checks that the skip changes nothing the server sees: tests/runtime_props_scene.mjs is bundled twice
+// with esbuild, as the theme is built, once as it is and once with the skip turned off (the runtime
+// before the change), and both must send exactly the same lord.* calls, in the same order, over fuzzed
+// trees, and end with the same styles. Also checks that the skip really ran. Needs node and the
+// repository's node_modules (esbuild, react, react-reconciler); run by tests/run_suites.sh.
+import { createRequire } from 'node:module';
+import { spawnSync } from 'node:child_process';
+import { mkdtempSync, writeFileSync, rmSync, readFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const here = path.dirname(fileURLToPath(import.meta.url));
+const root = path.resolve(here, '..', '..');
+const nodePaths = [path.join(root, 'node_modules'), ...(process.env.NODE_PATH || '').split(':').filter(Boolean)];
+let esbuild = null;
+for (const p of nodePaths) { try { esbuild = createRequire(path.join(p, 'x.js'))('esbuild'); break; } catch (e) { /* next */ } }
+if (!esbuild) { console.log('needs node_modules (esbuild)'); process.exit(1); }
+
+// The recording lord: every native call as a line, and each node's style as the server would hold it.
+const MOCK = `globalThis.__lordTest = (() => {
+ const log = [], state = new Map();
+ const fmt = (v) => (typeof v === 'number' ? (Object.is(v, -0) ? '-0' : String(v)) : v === undefined ? 'undef'
+ : JSON.stringify(v, (k, x) => (typeof x === 'number' && (x !== x || Object.is(x, -0)) ? String(x) + 'n' : x)));
+ let nextId = 1;
+ globalThis.lord = {
+ screen: { width: 1920, height: 1080, displays: [], mirror: false },
+ version: 'test', now: () => 0, stats: () => ({}), getLayout: () => [0, 0, 0, 0],
+ createNode: (t) => { const id = nextId++; log.push('create ' + t + ' ' + id); state.set(id, {}); return id; },
+ setStyle: (id, k, v) => { log.push('style ' + id + ' ' + k + ' ' + fmt(v)); const s = state.get(id); if (v === undefined) delete s[k]; else s[k] = v; },
+ setProp: (id, k, v) => log.push('prop ' + id + ' ' + k + ' ' + fmt(v)),
+ setText: (id, t) => log.push('text ' + id + ' ' + JSON.stringify(t)),
+ appendChild: (p, c) => log.push('append ' + p + ' ' + c),
+ insertBefore: (p, c, b) => log.push('insert ' + p + ' ' + c + ' ' + b),
+ removeChild: (p, c) => log.push('remove ' + p + ' ' + c),
+ destroy: (id) => log.push('destroy ' + id),
+ setRoot: (id) => log.push('root ' + id),
+ };
+ globalThis.__skips = 0;
+ process.on('exit', () => process.stderr.write('skips ' + globalThis.__skips + '\\n'));
+ return { log, fmt, state };
+})();`;
+
+const runtime = path.join(root, 'runtime', 'index.js');
+const SKIP_TEST = 'if (!sameFlat(flats.get(inst), flat)) {';
+// skip-off: the skip's test always fails, so every render normalizes and diffs as before the change.
+// Both variants count the applyProps calls the skip spares (or would spare).
+function variant(off) {
+ return {
+ name: off ? 'skip-off' : 'skip-on',
+ setup(b) {
+ b.onLoad({ filter: /runtime[\\/]index\.js$/ }, () => {
+ let src = readFileSync(runtime, 'utf8');
+ if (!src.includes(SKIP_TEST)) throw new Error('runtime/index.js: the skip test is not where this test expects it');
+ src = src.replace(SKIP_TEST, `if (sameFlat(flats.get(inst), flat)) globalThis.__skips++;\n if (${off ? 'true' : '!sameFlat(flats.get(inst), flat)'}) {`);
+ return { contents: src, loader: 'js', resolveDir: path.dirname(runtime) };
+ });
+ },
+ };
+}
+
+const dir = mkdtempSync(path.join(tmpdir(), 'lord-runtime-props-'));
+let bad = 0;
+try {
+ const files = {};
+ for (const off of [false, true]) {
+ const out = await esbuild.build({
+ entryPoints: [path.join(here, 'runtime_props_scene.mjs')], bundle: true, write: false, format: 'esm',
+ platform: 'node', target: 'es2022', nodePaths, logLevel: 'error',
+ alias: { '@lordos/runtime': runtime }, define: { 'process.env.NODE_ENV': '"production"' },
+ banner: { js: MOCK }, plugins: [variant(off)],
+ });
+ files[off ? 'off' : 'on'] = path.join(dir, off ? 'off.mjs' : 'on.mjs');
+ writeFileSync(files[off ? 'off' : 'on'], out.outputFiles[0].contents);
+ }
+ const run = (f, seed) => {
+ const r = spawnSync(process.execPath, [f, String(seed), '300'], { encoding: 'utf8', maxBuffer: 64 << 20 });
+ if (r.status !== 0) throw new Error(`${path.basename(f)} seed ${seed}: ${r.stderr}`);
+ const m = /skips (\d+)/.exec(r.stderr);
+ return { out: r.stdout, skips: m ? +m[1] : 0 };
+ };
+ let skips = 0, lines = 0;
+ for (let seed = 1; seed <= 8; seed++) {
+ const on = run(files.on, seed), off = run(files.off, seed);
+ skips += on.skips;
+ lines += on.out.split('\n').length - 1;
+ if (on.out !== off.out) {
+ bad++;
+ const a = on.out.split('\n'), b = off.out.split('\n');
+ let i = 0;
+ while (i < a.length && a[i] === b[i]) i++;
+ console.log(`✗ seed ${seed}: the calls differ at line ${i + 1}\n with the skip ${a[i]}\n without the skip ${b[i]}`);
+ }
+ }
+ if (!skips) { bad++; console.log('✗ the skip never ran: the test no longer exercises it'); }
+ console.log(`runtime-props: 8 seeds × 300 renders, ${lines} lines of native calls and final styles compared, ${skips} applyProps calls skipped, ${bad} failures`);
+} finally {
+ rmSync(dir, { recursive: true, force: true });
+}
+process.exit(bad ? 1 : 0);
diff --git a/server/tests/timer_order_test.c b/server/tests/timer_order_test.c
new file mode 100644
index 0000000..f9e1b07
--- /dev/null
+++ b/server/tests/timer_order_test.c
@@ -0,0 +1,268 @@
+/* timer_order_test.c — the timers of src/ui/js_prelude.h against the prelude they replaced.
+ *
+ * Until 0.8.6, __lordTick looked at every pending timer on every pass of the main loop and built
+ * an [id, timer] pair per timer. Now it keeps the earliest deadline and returns early when nothing
+ * is due (js_prelude.h). This test runs the same scripts on both, in QuickJS, and requires the
+ * same trace, byte for byte: which callbacks run, in which order, with which arguments, what the
+ * tick returns (the main loop's wait, %.17g) and what is logged. The scripts are random
+ * (seeded): setTimeout, setInterval and setImmediate with equal, zero, negative, fractional,
+ * NaN and string delays, clearTimeout of pending, fired, due and unknown ids, timers set and
+ * cleared from inside callbacks (also ones already due in that tick), callbacks that throw, and
+ * ticks whose `now` is behind the clock lord.now() reads. lord.now() is a deterministic clock that
+ * moves on each read, so both sides must also read it the same number of times.
+ *
+ * `build/timer-order-test bench` times a tick with nothing due and 200 timers pending, both ways. */
+#include "ui/js_prelude.h"
+
+#include "quickjs.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+/* The prelude as of 001633b (src/ui/js.c), the reference. */
+#define prelude old_prelude
+static const char prelude[] =
+ "(function(){\n"
+ "const g = globalThis;\n"
+ "const fmt = v => typeof v === 'string' ? v : v instanceof Error ? (v.message + '\\n' + (v.stack || '')) :\n"
+ " (() => { try { return JSON.stringify(v); } catch (e) { return String(v); } })();\n"
+ "const out = p => (...a) => lord.log(p + a.map(fmt).join(' '));\n"
+ "g.console = { log: out(''), info: out(''), debug: out(''), warn: out('[warn] '), error: out('[error] ') };\n"
+ "g.performance = { now: () => lord.now() };\n"
+ "let nextId = 1; const timers = new Map();\n"
+ "const add = (fn, ms, args, repeat) => { const id = nextId++; ms = Math.max(0, +ms || 0);\n"
+ " timers.set(id, { fn, args, at: lord.now() + ms, ms, repeat }); return id; };\n"
+ "g.setTimeout = (fn, ms, ...a) => add(fn, ms, a, false);\n"
+ "g.setInterval = (fn, ms, ...a) => add(fn, ms, a, true);\n"
+ "g.setImmediate = (fn, ...a) => add(fn, 0, a, false);\n"
+ "g.clearTimeout = g.clearInterval = g.clearImmediate = id => { timers.delete(id); };\n"
+ "g.queueMicrotask = fn => { Promise.resolve().then(fn); };\n"
+ "let frames = new Map(), frameId = 1;\n"
+ "g.requestAnimationFrame = fn => { const id = frameId++; frames.set(id, fn); return id; };\n"
+ "g.cancelAnimationFrame = id => { frames.delete(id); };\n"
+ "g.__lordTick = now => {\n"
+ " const due = [];\n"
+ " for (const [id, t] of timers) if (t.at <= now) due.push([id, t]);\n"
+ " due.sort((a, b) => a[1].at - b[1].at || a[0] - b[0]);\n"
+ " for (const [id, t] of due) {\n"
+ " if (!timers.has(id)) continue;\n"
+ " if (t.repeat) t.at = now + Math.max(t.ms, 1); else timers.delete(id);\n"
+ " try { t.fn(...t.args); } catch (e) { console.error('timer:', e); }\n"
+ " }\n"
+ " now = lord.now(); let next = -1;\n"
+ " for (const t of timers.values()) { const d = Math.max(0, t.at - now); if (next < 0 || d < next) next = d; }\n"
+ " return next;\n"
+ "};\n"
+ "g.__lordWantsFrame = () => frames.size > 0;\n"
+ "g.__lordFrame = now => { const f = frames; frames = new Map();\n"
+ " for (const fn of f.values()) { try { fn(now); } catch (e) { console.error('raf:', e); } } };\n"
+ "})();\n";
+#undef prelude
+
+/* the scripts: the same source on both sides, seeded */
+static const char script[] =
+ "(function(){\n"
+ "let s = (SEED >>> 0) || 1;\n"
+ "const rnd = n => { s ^= s << 13; s >>>= 0; s ^= s >>> 17; s ^= s << 5; s >>>= 0; return s % n; };\n"
+ "const ids = [], trace = []; globalThis.__trace = trace;\n"
+ "const delays = [0, 0, 0, 1, 1, 2, 5, 16, 16, 33, 100, 2.5, 0.25, -5, NaN, '7', undefined, 1e9];\n"
+ "let label = 0;\n"
+ "const pick = () => ids.length ? ids[rnd(ids.length)] : rnd(5);\n"
+ "const body = (L, depth) => (a, b) => {\n"
+ " trace.push('run ' + L + ' ' + a + b);\n"
+ " if (depth < 3) for (let i = rnd(4); i-- > 0;) op(depth + 1);\n"
+ " if (rnd(9) === 0) throw 'boom ' + L;\n"
+ "};\n"
+ "const op = depth => {\n"
+ " const k = rnd(12), L = label++;\n"
+ " if (k < 4) { const id = setTimeout(body(L, depth), delays[rnd(delays.length)], L, '/t'); ids.push(id); trace.push('timeout ' + L + '=' + id); }\n"
+ " else if (k < 6) {\n"
+ " let left = 1 + rnd(5); const f = body(L, depth);\n"
+ " const id = setInterval((a, b) => { f(a, b); if (--left === 0) { clearInterval(id); trace.push('stop ' + id); } }, delays[rnd(delays.length)], L, '/i');\n"
+ " ids.push(id); trace.push('interval ' + L + '=' + id);\n"
+ " }\n"
+ " else if (k < 7) { const id = setImmediate(body(L, depth), L, '/m'); ids.push(id); trace.push('immediate ' + L + '=' + id); }\n"
+ " else if (k < 10) { const id = pick(); clearTimeout(id); trace.push('clear ' + id); }\n"
+ " else if (k < 11) { const id = pick(); clearInterval(id); clearImmediate(id); trace.push('clear2 ' + id); }\n"
+ " else { clearTimeout('' + pick()); trace.push('clear string'); }\n"
+ "};\n"
+ "globalThis.__poke = () => { for (let i = rnd(5); i-- > 0;) op(0); };\n"
+ "})();\n";
+
+/* the clock lord.now() reads: it moves on every read, by steps that are often 0 (equal deadlines) */
+static double clk;
+static unsigned crng;
+static unsigned rnd(unsigned n) { crng ^= crng << 13; crng ^= crng >> 17; crng ^= crng << 5; return crng % n; }
+
+static char *logbuf;
+static size_t loglen, logcap;
+static void put(const char *s) {
+ size_t n = strlen(s);
+ if (loglen + n + 2 > logcap) {
+ logcap = (loglen + n + 2) * 2;
+ logbuf = realloc(logbuf, logcap);
+ if (!logbuf) { perror("realloc"); exit(2); }
+ }
+ memcpy(logbuf + loglen, s, n);
+ loglen += n;
+ logbuf[loglen++] = '\n';
+ logbuf[loglen] = 0;
+}
+
+static JSValue f_now(JSContext *c, JSValueConst this_val, int argc, JSValueConst *argv) {
+ (void)this_val; (void)argc; (void)argv;
+ static const double steps[] = { 0, 0, 0, 0.25, 1, 4, 16.666666666666668 };
+ double t = clk;
+ clk += steps[rnd(sizeof steps / sizeof *steps)];
+ return JS_NewFloat64(c, t);
+}
+
+static JSValue f_log(JSContext *c, JSValueConst this_val, int argc, JSValueConst *argv) {
+ (void)this_val;
+ const char *s = argc > 0 ? JS_ToCString(c, argv[0]) : NULL;
+ put(s ? s : "(log)");
+ if (s) JS_FreeCString(c, s);
+ return JS_UNDEFINED;
+}
+
+static int eval(JSContext *c, const char *src, const char *name) {
+ JSValue r = JS_Eval(c, src, strlen(src), name, JS_EVAL_TYPE_GLOBAL);
+ int ok = !JS_IsException(r);
+ if (!ok) {
+ JSValue e = JS_GetException(c);
+ const char *m = JS_ToCString(c, e);
+ fprintf(stderr, "%s: %s\n", name, m ? m : "?");
+ if (m) JS_FreeCString(c, m);
+ JS_FreeValue(c, e);
+ }
+ JS_FreeValue(c, r);
+ return ok;
+}
+
+static void drain(JSRuntime *rt) {
+ JSContext *c;
+ while (JS_ExecutePendingJob(rt, &c) > 0) {}
+}
+
+static JSValue call(JSContext *c, const char *name, int argc, JSValueConst *argv) {
+ JSValue g = JS_GetGlobalObject(c), f = JS_GetPropertyStr(c, g, name);
+ JSValue r = JS_Call(c, f, g, argc, argv);
+ JS_FreeValue(c, f);
+ JS_FreeValue(c, g);
+ return r;
+}
+
+static JSContext *new_context(JSRuntime *rt, const char *prel) {
+ JSContext *c = JS_NewContext(rt);
+ JSValue g = JS_GetGlobalObject(c), lord = JS_NewObject(c);
+ JS_SetPropertyStr(c, lord, "now", JS_NewCFunction(c, f_now, "now", 0));
+ JS_SetPropertyStr(c, lord, "log", JS_NewCFunction(c, f_log, "log", 1));
+ JS_SetPropertyStr(c, g, "lord", lord);
+ JS_FreeValue(c, g);
+ if (!eval(c, prel, "<prelude>")) exit(2);
+ return c;
+}
+
+/* One run: the trace (C log, then the script's own) in logbuf. */
+static long fires;
+static void run(const char *prel, unsigned seed, int steps) {
+ loglen = 0;
+ if (logbuf) logbuf[0] = 0;
+ clk = 1000.125;
+ crng = seed * 2654435761u + 1;
+ JSRuntime *rt = JS_NewRuntime();
+ JSContext *c = new_context(rt, prel);
+ char src[sizeof script + 64];
+ snprintf(src, sizeof src, "const SEED = %u;\n%s", seed, script);
+ if (!eval(c, src, "<script>")) exit(2);
+ static const double adv[] = { 0, 0, 0.25, 1, 2, 7, 16.666666666666668, 50, 200, -3 };
+ double now = clk;
+ for (int i = 0; i < steps; i++) {
+ char line[96];
+ if (rnd(3) == 0) {
+ JS_FreeValue(c, call(c, "__poke", 0, NULL));
+ put("poke");
+ } else {
+ now += adv[rnd(sizeof adv / sizeof *adv)];
+ if (rnd(4) == 0 && now < clk) now = clk; /* catch up with the clock now and then */
+ JSValue arg = JS_NewFloat64(c, now);
+ JSValue r = call(c, "__lordTick", 1, &arg);
+ double next = -2;
+ if (JS_IsException(r)) put("tick threw");
+ else JS_ToFloat64(c, &next, r);
+ JS_FreeValue(c, r);
+ snprintf(line, sizeof line, "tick %.17g -> %.17g (clock %.17g)", now, next, clk);
+ put(line);
+ }
+ drain(rt);
+ }
+ JSValue g = JS_GetGlobalObject(c), tr = JS_GetPropertyStr(c, g, "__trace");
+ JSValue js = JS_JSONStringify(c, tr, JS_UNDEFINED, JS_NewInt32(c, 0));
+ const char *s = JS_ToCString(c, js);
+ put(s ? s : "(no trace)");
+ for (const char *p = s; p && (p = strstr(p, "\"run ")); p++) fires++;
+ if (s) JS_FreeCString(c, s);
+ JS_FreeValue(c, js);
+ JS_FreeValue(c, tr);
+ JS_FreeValue(c, g);
+ JS_FreeContext(c);
+ JS_FreeRuntime(rt);
+}
+
+static double ms(void) {
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return t.tv_sec * 1e3 + t.tv_nsec / 1e6;
+}
+
+/* a tick with nothing due among 200 pending timers (a React app, the clock, polls) */
+static double bench(const char *prel) {
+ JSRuntime *rt = JS_NewRuntime();
+ JSContext *c = new_context(rt, prel);
+ if (!eval(c, "for (let i = 0; i < 200; i++) setTimeout(() => {}, 1e7 + i);", "<bench>")) exit(2);
+ const int n = 20000;
+ double t0 = ms();
+ for (int i = 0; i < n; i++) {
+ JSValue arg = JS_NewFloat64(c, 1000 + i * 0.001);
+ JS_FreeValue(c, call(c, "__lordTick", 1, &arg));
+ drain(rt);
+ }
+ double per = (ms() - t0) / n * 1000;
+ JS_FreeContext(c);
+ JS_FreeRuntime(rt);
+ return per;
+}
+
+int main(int argc, char **argv) {
+ if (argc > 1 && !strcmp(argv[1], "bench")) {
+ printf("timer-order-test bench: a tick with 200 timers pending, nothing due: before %.2f us, now %.2f us\n",
+ bench(old_prelude), bench(prelude));
+ return 0;
+ }
+ const unsigned seeds = 400;
+ const int steps = 300;
+ int fails = 0;
+ long bytes = 0;
+ for (unsigned seed = 1; seed <= seeds; seed++) {
+ run(old_prelude, seed, steps);
+ char *want = strdup(logbuf ? logbuf : "");
+ long f0 = fires;
+ run(prelude, seed, steps);
+ fires = f0; /* counted once */
+ if (!want || strcmp(want, logbuf ? logbuf : "")) {
+ if (fails++ < 3) {
+ size_t i = 0;
+ while (want && want[i] && want[i] == logbuf[i]) i++;
+ size_t from = i > 200 ? i - 200 : 0;
+ printf("✗ seed %u differs at byte %zu:\n before: %.300s\n now: %.300s\n", seed, i, want + from, logbuf + from);
+ }
+ }
+ bytes += (long)loglen;
+ free(want);
+ }
+ printf("timer-order-test: %u random scripts, %ld callbacks run, %ld bytes of trace compared, %d differ\n",
+ seeds, fires, bytes, fails);
+ return fails ? 1 : 0;
+}