Hazel reports Β· ^report(32) Β· Messed Up Dress Up's scripts Β· 2026-10-23 Β· work in progress

Scripting, Three Ways, Timed

Matthew: please do a report about loading the game with fumola as default, scrolling to check each script as a speed run; hazel, same speed run, and Oh, and JS as default too. (^ticket(588))

Short answers.

  1. Opening the tab costs nothing for any of the three: Common's box is there 50–70 ms after the tab opens (JS 51, Fumola 67, Hazel 68 ms in the first round; about the same after).
  2. Fumola is ready in 0.7 s the first time, under 0.1 s after (695 ms, then 92 and 69 ms): the first round fetches and compiles its wasm; later rounds find it in the browser's cache. Hazel's library was already loaded when the tab opened (54–72 ms), as the game loads it at the start when the saved scripts use it.
  3. Hazel's tiles take about 3.7 s for all six boxes (median; 3.0 to 4.5 s), Common's first at about 2.9 s, then one box after another, as they are now made one at a time. The page keeps drawing while they load: about 58 frames a second.
  4. The game calling into a script: Fumola's rule answers in about 1.6 ms, Hazel's in about 3.5 ms (medians of 60 lever pulls each). The commands the rule gives then take the game about 9 ms with either, the same work the game's own JS does: a whole pull is 9.7 ms with JS, 10.7 ms with Fumola, 13.7 ms with Hazel. So a rule adds about 1 ms in Fumola and 4 ms in Hazel to an event, under a quarter of a 60 Hz frame.
  5. But Hazel has one slow event in every round: 0.5 to 0.7 s (502, 692, 519 ms), the first pull after the state is reset, which compiles the program; Fumola's slowest pull is 12–21 ms. That one pause is the thing a player would feel.
  6. Scrolling through the scripts and visiting each at max size runs at about 58 frames a second in all three, with two or three frames over 50 ms each run; the longest single frames (0.4–1.5 s) come in the first round or the first visit, cold, in every mode, JS included.
  7. As the code grows, Fumola does not slow down, and Hazel does, then stops. An edit (a definition added to Common) is ready again after about 125 ms in Fumola at every size, up to 16 times Common (728 lines). In Hazel it takes about 360 ms at Common's size, 435 ms at twice, 745 ms at four times; at eight times (184 lines of Common) the game's Hazel build runs out of stack (Stack_overflow) compiling it, and the rooms go back to their JS. The event itself barely moves with size: about 1.1 ms in Fumola and 3 ms in Hazel at every size that runs.

Try it#

From the tab opened to ready#

The median of 3 rounds, each from a fresh page. JS has nothing to load: its boxes show the game's own code at once. Fumola loads its wasm build and defines the rules; Hazel loads its JS library and compiles the program, and then, with the boxes in tiles (the default), makes one frame of Hazel's own app per box, one at a time.

JS: tab open51 msFumola: engine ready92 msHazel: engine ready68 msHazel: Common's tiles2.9 sHazel: TrapRoom's tiles3.7 sHazel: TreeRoom's tiles3.7 sHazel: Square's tiles3.7 sHazel: World's tiles3.7 sHazel: Castle's tiles3.7 s

Every measure#

Each a median over the rounds, with the rounds' range in brackets. Times from the tab opened; frame times are the game's own (the gaps between its animation frames), so a frame over 50 ms is one a player can feel.

measureJS as defaultFumola as defaultHazel as default
tab open to Common's box51 ms (44–60)69 ms (67–91)67 ms (54–71)
engine ready–92 ms (69–695)68 ms (54–72)
Common's tiles ready––2,948 ms (2,772–3,688)
TrapRoom's tiles ready––3,676 ms (2,948–3,688)
TreeRoom's tiles ready––3,676 ms (2,998–3,739)
Square's tiles ready––3,676 ms (2,998–4,541)
World's tiles ready––3,676 ms (2,998–4,541)
Castle's tiles ready––3,676 ms (2,998–4,541)
loading: median frame–16.7 ms16.7 ms
loading: 95th percentile frame–166.6 ms16.8 ms (16.7–16.8)
loading: longest frame–167 ms67 ms (50–67)
loading: frames over 50 ms00 (0–2)1 (1–2)
loading: frames a second–22.158.3 (58.3–59.1)
scrolling each box into view: median frame16.7 ms16.7 ms16.7 ms
scrolling: 95th percentile16.8 ms (16.7–16.8)16.8 ms (16.7–16.8)16.8 ms
scrolling: longest frame67 ms (67–1,483)83 ms (67–367)67 ms (67–67)
scrolling: frames over 50 ms2 (2–3)2 (1–2)3 (2–3)
scrolling: frames a second57.4 (42.3–57.6)58.3 (54.8–58.8)57.9 (57.9–58.1)
visiting each box at max size: median frame16.7 ms16.7 ms16.7 ms
visiting: 95th percentile16.8 ms16.7 ms (16.7–16.8)16.8 ms
visiting: longest frame467 ms (67–533)33 ms (17–433)100 ms (67–683)
visiting: frames over 50 ms3 (2–4)0 (0–1)8 (7–9)
visiting: frames a second52.4 (51.9–57.9)59.8 (54.7–60.0)54.4 (47.0–54.6)
events: the game's call into the script function (median)–1.600 ms (1.600–1.700)3.500 ms (3.500–4.000)
events: the script function, 95th percentile–2.600 ms (2.300–4.100)6.200 ms (4.700–10.000)
events: the script function, longest–2.600 ms (2.300–4.100)6.200 ms (4.700–10.000)
events: the commands it gave, run by the game (median)–9.100 ms (8.900–9.200)9.100 ms (9.000–10.300)
events: the whole event, engine to commands done (median)9.700 ms (9.100–10.000)10.700 ms (10.700–11.300)13.700 ms (13.300–14.300)
events: the whole event, longest11.000 ms (10.600–17.100)17.300 ms (12.000–21.100)519.200 ms (502.000–691.400)
events: a lever pull, at the game's entry point (median)9.700 ms (9.100–10.100)11.000 ms (10.900–11.600)13.900 ms (13.600–14.500)
events: a lever pull, longest11.200 ms (10.600–17.400)17.700 ms (12.200–21.500)519.400 ms (502.300–691.600)
long tasks (over 50 ms), all phases3 (1–3)3 (3–4)3
long tasks' total time534 ms (472–2,007)630 ms (562–959)1,277 ms (1,248–1,720)
the whole run, tab to end13,055 ms (12,930–14,226)13,112 ms (13,056–13,701)17,419 ms (17,295–18,333)

The game calling into a script#

Matthew: let's include timing for event "event handler", or Game Engine ---calls-into-script---> Script Function. In each round, after the tab's runs, the trap room's red levers are pulled 20 times, left and right in turn, each through the game's own entry point (roomLeverPull), which hands the event to the room's rule when one runs it (scriptEvent), and to the game's JS when not. The game times each hop itself (hzCounters, 25-scripting.js): the script function alone (the event in, the commands out), the commands then run by the game, the whole event; and, for JS, its own handler. The table's rows starting "events" are these, in milliseconds to the thousandth.

JSevent 9.7 msthe game's ownFumolaevent 10.7 msscript 1.6 msHazelevent 13.7 msscript 3.5 ms

Each engine: the pale bar the whole event (the game's call to the commands done), the dark bar the script function alone (the event in, the rule's answer out). JS's handler is the game's own code, so it has the whole event only. Medians of 60 pulls (three rounds of 20).

What the numbers say#

As the code grows, and as we edit#

Matthew: Can we project what will happen if the code gets bigger? ... what happens as we edit? Let's measure and plot response to edits that are valid logic edits (how long does the program take to complete the edit and be ready to be responsive)? Common, made 1, 2, 4, 8 and 16 times its size with renamed copies of its functions, in Hazel and in Fumola. At each size, five edits, each a definition added to Common (a valid logic edit: the program changes, and stays fine), each timed from the change to the rules compiled and ready to answer the next event (the game waits 600 ms after typing stops before it starts this); Hazel's analysis of the whole program, the work its tiles redo after an edit; and one event's script function.

016432749165581823466992112200376728the program's lines (Common at 1, 2, 4, 8, 16 times its size)msHazel: an edit, until readyFumola: an edit, until readyHazel: the whole program analyzed (the tiles' work)Hazel: the script function, one eventFumola: the script function, one event
enginesizelinesfirst compilean edit, until ready (median of 5)Hazel's analysisscript function, one event
hazel1Γ—230.1 ms357.5 ms (326.5–476.6)260 ms3 ms
hazel2Γ—46575.2 ms435.4 ms (412.4–566.3)302 ms2.7 ms
hazel4Γ—92649.1 ms744 ms (650.9–952.9)428 ms3.2 ms
hazel8Γ—184not ready after an edit: 248,Stack_overflow,-9
hazel16Γ—368not ready at first: 248,Stack_overflow,-9
fumola1Γ—69208 ms129.3 ms (114.6–134.5)–1.2 ms
fumola2Γ—112119 ms125 ms (119.2–137.3)–1.2 ms
fumola4Γ—200122.4 ms120.9 ms (115.4–144)–1.1 ms
fumola8Γ—376122.8 ms131.7 ms (119.2–149.7)–1.1 ms
fumola16Γ—728124.8 ms124.2 ms (121.4–146)–1.1 ms

The pit room's rule, three ways#

Matthew: let's also show each room with an interesting script, and an example of the three scripts for that room: pit room? include screenshot in report. The trap room over the castle's dungeons, whose rule has the most to it: a red lever flips, and the pits wired to it open or shut; a blue lever gives a pit its boulder or takes it away.

The trap room in the game: its two red levers, the pits they open, the boulders' blue levers.
The trap room in the game: its two red levers, the pits they open, the boulders' blue levers.
Its rule at max size, in Hazel's tiles, with the outline of every box at the left.
Its rule at max size, in Hazel's tiles, with the outline of every box at the left.
πŸ“š Common at max size, in its tiles: the definitions every room calls, each function's type at the left as Hazel infers it, then the program's types with their kinds and cases.
πŸ“š Common at max size, in its tiles: the definitions every room calls, each function's type at the left as Hazel infers it, then the program's types with their kinds and cases.

Its rule, three ways: the game's own JS (the functions the game runs, shown read-only), the Hazel rule and the Fumola rule, each from the run's page, as the game ships them. The Hazel and Fumola rules call Common's helpers (Common.wire, Common.pits_open, Common.pit_moves), and give back commands (Flip, SetPit, LiftBoulder, DropBoulder), which the game then runs, as its JS does directly.

JS (the game's own)
function roomLeverPull(side) {
  if (side[0] === "B") return roomBoulderPull(side.slice(1));   // (ticket 323: a blue one)
  if (side === "H") return hatchLeverPull();   // (ticket 334: a tree room's trap door's)
  if (scriptEvent("TrapRoom", { tag: "Pull", value: side })) return;   // (ticket 482: πŸ“œ Scripting's rule for the trap room, when it is on)
  hzJs("Pull", () => roomLeverFlip(side));   // (ticket 531: timed as the rule is)
}

function roomLeverFlip(side, lids = true) {
  const B = state.background;
  if (B.kind !== "castleroom") return;
  const K = castleOf(B), n = Math.max(1, Math.min(K.rooms.length, Math.round(B.castleRoom ?? 1))), key = leverKey(side, n, K.id);
  const was = trapState(B, n, K.id).open;
  B[key] = !leverDown(B, side, n, K.id);   // (ticket 307: never touched, it was down)
  changed();
  const up = !B[key], sd = side === "L" ? -1 : 1, T = trapState(B, n, K.id), now = T.open;
  turnArm(`[data-lever="${side}"] .lever-arm`, (up ? 1 : -1) * sd * LEVER_TILT, LEVER_TURN * 100 / T.speed.lever);   // (ticket 328: the room's speeds)
  if (!lids) return;
  for (const j of [0, 1]) if (now[j] !== was[j]) lidSwing(`.pit-lid[data-pit-i="${j}"]`, now[j], PIT_SWING * 100 / T.speed.lid);   // (ticket 307)
  // (Matthew: "opened by the red lever (trap door) while standing on it, and no falling sequence was triggered") a pit opened
  // under the friend: in they fall, as walking onto it does, once its lid has swung most of the way
  if (now.some((o, j) => o && !was[j])) setTimeout(fallIfOverPit, 0.6 * PIT_SWING * 100 / T.speed.lid);
}

function roomBoulderPull(side) {
  if (scriptEvent("TrapRoom", { tag: "PullBoulder", value: side })) return;   // (ticket 531: πŸ“œ TrapRoom's rule, when it is on)
  hzJs("PullBoulder", () => {
    const B = state.background;
    if (B.kind !== "castleroom") return;
    const K = castleOf(B), n = Math.max(1, Math.min(K.rooms.length, Math.round(B.castleRoom ?? 1)));
    // (ticket 338) the pits this lever works: a fallen rock still on any, lifted away (each rising, and gone from the place's
    // things); else into each a new rock falls, which once landed is a placed rock, "fallen N", dragged where one likes
    const T0 = trapState(B, n, K.id), mine = [0, 1].filter(j => T0.wire[j] === side && T0.on[j]), lift = mine.some(j => T0.covered[j]);
    roomBoulderAct(side, mine, lift);
  });
}
Hazel
# A red lever pulled: flip it, and each pit wired to it opens or shuts. #
# A blue lever pulled: each of its pits gets a boulder, or loses one. #
let on_event = fun (g, e) : (Globals, Event) ->
  let w = Common.wire(g.wiring, g.draws) in
  let (w0, w1) = w in
  case e
  | Pull(side) =>
    let (was0, was1) = Common.pits_open(g.lever_L, g.lever_R, w) in
    let l = if side == L then !g.lever_L else g.lever_L in
    let r = if side == R then !g.lever_R else g.lever_R in
    let (now0, now1) = Common.pits_open(l, r, w) in
    Flip(side, Common.pit_moves(0, was0, now0, Common.pit_moves(1, was1, now1, Done)))
  | PullBoulder(side) =>
    let mine0 = w0 == side && Common.nth(g.pits_on, 0) in
    let mine1 = w1 == side && Common.nth(g.pits_on, 1) in
    let lift = (mine0 && Common.nth(g.covered, 0)) || (mine1 && Common.nth(g.covered, 1)) in
    let one = fun (i, mine, k) : (Int, Bool, Cmd) -> if !mine then k else if lift then LiftBoulder(i, k) else DropBoulder(i, k) in
    one(0, mine0, one(1, mine1, Done))
  | _ => Done
  end
Fumola
module TrapRoom {
  // a blue lever's pit i: nothing if not its own, else its rock lifted or a rock dropped
  func one(i : Int, mine : Bool, lift : Bool, k : Common.Cmd) : Common.Cmd { if (not mine) { k } else if (lift) { #LiftBoulder(i, k) } else { #DropBoulder(i, k) } };
  // A red lever pulled: flip it, and each pit wired to it opens or shuts.
  // A blue lever pulled: each of its pits gets a boulder, or loses one.
  public func on_event(g : Common.Globals, e : Common.Event) : Common.Cmd {
    let w = Common.wire(g.wiring, g.draws);
    let (w0, w1) = w;
    switch (e) {
      case (#Pull(side)) {
        let (was0, was1) = Common.pits_open(g.lever_L, g.lever_R, w);
        let l = if (side == #L) { not g.lever_L } else { g.lever_L };
        let r = if (side == #R) { not g.lever_R } else { g.lever_R };
        let (now0, now1) = Common.pits_open(l, r, w);
        #Flip(side, Common.pit_moves(0, was0, now0, Common.pit_moves(1, was1, now1, #Done)))
      };
      case (#PullBoulder(side)) {
        let mine0 = (w0 == side) and Common.nth(g.pits_on, 0);
        let mine1 = (w1 == side) and Common.nth(g.pits_on, 1);
        let lift = (mine0 and Common.nth(g.covered, 0)) or (mine1 and Common.nth(g.covered, 1));
        one(0, mine0, lift, one(1, mine1, lift, #Done))
      };
      case _ { #Done }
    }
  }
}

The same answers, three ways#

Matthew: what can we say about our CI tests for 3-way functional correctness in this doc? Speed means nothing if the rules disagree, so the game holds Hazel's and Fumola's rules to its own JS on every push. Its test workflow has a step The rules three ways, JS = Hazel = Fumola (^ticket(567)), with no browser, node only, and two checks:

Reading the table. A case is one situation a room can be in (its globals) and one event; a comparison is one answer checked against the JS's answer for that case. Each Hazel case is one call, so its cases and its comparisons are the same number. Fumola's page has two modes (the World map held in Fumola, or passed in with each event), and every Fumola case is asked in both, so it makes two comparisons; Common's helpers are called once, outside either mode. A few checks are not calls at all (the program compiles; the boundary refuses what it cannot write), and count one each. The last row adds each column up to the totals in the text above.

what is comparedHazel: cases (= comparisons)Fumola: casesFumola: comparisons (cases × modes)the JS's answer comes from
the trap room's red and blue levers2,3042,304× 2 = 4,608trapWiring, the game's own (01-state.js), with its seeded draws (10-nature.js); the levers' outcomes restated from their few lines of JS
the tree houses' and round room's hatches1414× 2 = 28restated from the hatch lever's JS
placed levers and their trap doors108108× 2 = 216the game's own leverPull and leverPullApply (26-drags-and-start.js), on a stand-in square
the castle's pits, where a fall lands1,5601,560× 2 = 3,120the pits line as castleroomScene draws it
ways out of a room26,4783,978× 2 = 7,956the game's own wayOutOf, the 12 room kinds read from ROOM_KINDS
the world's ways, square to square2,2962,296× 2 = 4,592the game's own worldMeets
edges named one by one, commands written out—41× 2 = 82written in the check
Common's helpers called alone—42× 1 = 42written in the check
the program is ready (compiled, no errors)1not a call: checked once
the Fumola source is ASCII; the list mode holds no map; a text with a quote is refused; literals written as the page writes them5not a call: checked once
comparisons in all32,76120,649

Where the game's JS can run in node, the expected answer is that code itself, not a copy of it: the wiring (trapWiring), the placed levers (leverPull), the ways out (wayOutOf), the world's ways (worldMeets). Only the red, blue and hatch levers' outcomes are restated in the check, from their few lines of JS. The step is allowed to fail so that the rest of the run still goes ahead, and a last step then fails the run if the rules disagreed. A difference shows as a red run on the branch, after the pictures and the other checks have run.

In the browser, two more checks play the same events in real pages and compare the game's state afterwards: tools/checks/hazellogic531.mjs (?logic=js against ?logic=hazel) and tools/checks/fumola542.mjs (against ?logic=fumola and ?logic=fumola-list). They cover the trap room wired at random, the hatches, a room of placed levers, the pits under four lever settings, the dungeons' ladders, and a world walked as a player walks it. They run with the branch's other checks on GitHub.

Where it stands: at the game's 370f532, the three-way step passed on GitHub (run 40053184542), and both checks print all ok when run in node on the laptop at the same commit (their output beside this report: Hazel, Fumola). Earlier runs on the branch were cancelled by the pushes that followed them, so this is the first one to reach that step since the outline work.

What it does not cover:

The same cases are the seed for unit tests in Hazel's library itself (hazelgrove/hazel#2711, ^ticket(591)), so that the library keeps giving these answers, not just this game.

What next#

  1. Find the recursion behind Hazel's stack overflow on a long module (statics over a chain of lets, in the js_of_ocaml build), fix it on the library's branch (#2711), and add the 8x program as a test (^ticket(591)).
  2. Find and remove Hazel's first-event pause: compile the program when the tab opens or the scripts change (the game already compiles ahead under ?logic=hazel), not on the first lever pulled; then measure the first pull again.
  3. Measure the same on the laptop and on the iPad, by hand from the game's πŸ”¬ timings once ^ticket(568) shows them, against these runner numbers.
  4. Time the other rooms' events (the world's ways, the castle's pits, placed levers), whose rules do more than the trap room's; the World rule on a big map is where ^report(30) found Hazel slow.
  5. Re-run after ^ticket(587) (the outline from Hazel) and with Hazel's tiles loaded on demand only, to see what the tiles cost the tab.

How this was put together#

The check tools/checks/scriptspeed588.mjs (kids-choice-games), run on GitHub's computers (no test browsers run on the laptop) on a branch carrying only it: diag-588, the game at d2ccd0a (diag-588, on script-boxes-566 430fc14) (the script-boxes-566 branch, with the tiles made one at a time), run 40034928882, GitHub's ubuntu-latest runner, Chrome headless. Hazel's tiles came from hazel.org/build/embed-editable/ as it was then (embed-editable, b029bbd1de or cb77919b10 (published 16:20)); the levers' Hazel from js-library-embed.

Each round: a fresh page; the game's state reset; every room's default set to one engine (Hazel's boxes in tiles); the πŸ“œ Scripting tab opened; the time until Common's box is there, until the engine is ready, and, with Hazel, until each box's tiles say ready; then each script box scrolled into view in turn, 600 ms each; then each box opened at max size from the outline, 600 ms each. The game's animation-frame gaps are recorded for each phase, and the long tasks (over 50 ms) throughout. Rounds in the order JS, Fumola, Hazel, three times. A single runner, so the noise between rounds is the range shown; the runner is not the laptop, and a phone is slower again.

The data#