Hazel reports · ^report(49) · hazel-jit · 2026-11-08, updated 2026-11-08 20:20 MST · work in progress · for the meeting with Cyrus on Wednesday 2026-11-11 (^report(42))

The Witch’s Run, Compiled, in the Page

What happens to one step of a slider when the slide's whole program, compiled to JavaScript by hazel-jit, runs in the page at the slider's event, instead of the page waiting for Hazel's worker to run it? ^report(45) measured the compiled run in Node: 2.3 to 2.5 ms a step on the Witch slide, against the interpreter's 684 ms (the whole run, compiled). This report is the same idea in the app, in Firefox, on 2026-11-08 (^ticket(722)), toward Matthew's goal for small edits that morning: "a floor of 60FPS for small edits (sliders changing), just like in JS".

Try it yourself: the branch's build, with a frame-rate overlay (?hud) showing the frames your browser draws: the Witch, compiled, and the same with nothing compiled. Drag a slider and watch the picture and the overlay. Everything runs in your own browser (hazelgrove/hazel#2817).

Update, 2026-11-08 night: the steps back are fixed (the steps back), and the numbers in this report now come from the run after the fix, 42554043524 at a51dc778dd: on all four steps the picture showed at the page's first redraw. The run before it, with two of four, is in the runs and its data.

Outline#

  1. A step, run compiled: the slide's run answers a step in 8 to 21 ms in Firefox, and the picture showed at the page's first redraw in 4 of 4 steps.
  2. Where a step's time goes now: the page's own work, 286 to 386 ms to its first redraw; the worker still runs and redraws everything again.
  3. The steps back: on a slider's return to its starting value the answers were at first dropped after one redraw, taken for an undo; fixed.
  4. What the Node numbers assumed: a slide's program, as the page holds it, has no livelit views in it; the compiled run now folds them in itself.
  5. The same drawings: on all 6 polygon slides, compiled and not, no differences.
  6. What it costs: the edited program compiled again after every step, 143 to 184 ms on the page's thread.
  7. Five runs: what each change did, in order.
  8. What next, and how this was put together.

A step, run compiled#

On the Witch slide in Firefox, the slide's whole program, compiled, runs at a slider's event in 8 to 21 ms (about 48 to 125 fps), all 53 of its livelits' views included, and in 2 to 3 ms for the next event of the same step. In 4 of 4 steps the picture changed at the page's first redraw, 286 to 386 ms after the event, from the compiled run's answers; with nothing compiled the same steps took 1.35 to 1.74 s. The run itself is now about a frame or less (8 to 21 ms at a step's first event, 2 to 3 ms at the next); what is not is the page around it: 286 to 386 ms is 17 to 23 frames, against 81 to 105 with nothing compiled.

One step of a slider on the Witch slide, in Firefox: each part, from the slider's event (a log scale)the slide's run, compiled: a step's first eventthe slide's run, compiled: a step's first event: 8 to 21 ms (4 readings, run 42554043524)8 to 21 ms, about 48 to 125 fpsthe same, the step's next event (a drag)the same, the step's next event (a drag): 2 to 3 ms (4 readings, run 42554043524)2 to 3 ms, about 333 to 500 fpsthe picture, drawn from the compiled runthe picture, drawn from the compiled run: 286 to 386 ms (4 readings, run 42554043524)286 to 386 ms, 17 to 23 framesthe slider's own livelit redrawnthe slider's own livelit redrawn: 286 to 386 ms (4 readings, run 42554043524)286 to 386 ms, 17 to 23 framesthe picture, nothing compiledthe picture, nothing compiled: 1352 to 1744 ms (4 readings, run 42554043524)1.35 to 1.74 s, 81 to 105 frames16.7 ms: 60 fps, the floor1 ms10 ms100 ms1000 ms
Four steps of two sliders (neck 28 to 30 and back, arms 55 to 65 and back), each bar from the fastest to the slowest of them; the grey bars with nothing compiled are the same four steps after a fresh load. Firefox on GitHub's machines, a release build of trial/694-view-jit at a51dc778dd, run 42554043524. A step is two events (the slider's input, then its change), so the compiled run is called twice; the second is warm. The frames assume nothing else in the frame costs anything.

A step of a slider is two events, its input and then its change, and the page calls the compiled run at each with the slider's new model as the run's argument. The run answers with every livelit's view, as JavaScript values, and each livelit is drawn straight from its answer (as compiled views are, ^report(45)) until the worker's run comes back. The steps, each event's run, and when the slider and the picture changed:

views compiledthe stepthe compiled run, each event (ms)compiled again after (ms)the slider redrawn (ms)the picture (ms)
onneck 28 to 309, 2149386386
onneck 30 to 288, 3159286286
onarms (up / down) 55 to 6521, 2143289289
onarms (up / down) 65 to 559, 2184381381
offneck 28 to 30--4281744
offneck 30 to 28--2851388
offarms (up / down) 55 to 65--2881622
offarms (up / down) 65 to 55--2521352

Where a step's time goes now#

The page first redraws 286 to 386 ms after the slider's event, and nearly all of that is its own work: the whole slide's view, twice (177 to 230 ms), its layout (53 to 97 ms), and the program's syntax and statics (49 to 87 ms). The compiled run is the sliver at the start. Meanwhile the worker still runs the program (0.74 to 1.01 s of work), and when its answer comes back the page draws every view again (179 to 273 ms), to the same picture.

One step (neck 30 to 28, views compiled): the picture at 286 ms, the worker's answer at 1.33 sthe slide's run, compiledhazel-jit: the run: 8 ms at 0 mshazel-jit: the run: 3 ms at 8 msthe page: update, statics, viewupdate: 13 ms at 12 mssyntax: 13 ms at 25 mscalculate: 14 ms at 25 mscursor info: 1 ms at 38 mscolor map: 0 ms at 39 msview: 87 ms at 39 msupdate: 9 ms at 126 mscalculate: 44 ms at 135 msstatics: 27 ms at 136 mssyntax: 12 ms at 163 mscursor info: 0 ms at 179 mscolor map: 0 ms at 179 msview: 94 ms at 179 msafter display: 3 ms at 283 msafter display: 0 ms at 452 msupdate: 0 ms at 469 mscalculate: 60 ms at 469 mssyntax: 14 ms at 470 mssyntax: 8 ms at 521 mscursor info: 0 ms at 529 mscolor map: 0 ms at 529 msview: 78 ms at 529 msafter display: 0 ms at 616 msafter display: 0 ms at 622 msafter display: 1 ms at 635 msafter display: 1 ms at 651 msafter display: 0 ms at 668 msafter display: 0 ms at 685 msafter display: 1 ms at 701 msafter display: 0 ms at 718 msafter display: 0 ms at 735 msafter display: 0 ms at 752 msafter display: 0 ms at 769 msafter display: 1 ms at 785 msafter display: 1 ms at 801 msafter display: 1 ms at 818 msafter display: 0 ms at 835 msafter display: 1 ms at 851 msafter display: 0 ms at 869 msafter display: 1 ms at 885 msafter display: 0 ms at 902 msafter display: 0 ms at 918 msafter display: 0 ms at 935 msafter display: 1 ms at 951 msafter display: 0 ms at 968 msafter display: 0 ms at 985 msafter display: 0 ms at 1002 msafter display: 0 ms at 1019 msafter display: 0 ms at 1035 msafter display: 1 ms at 1051 msafter display: 0 ms at 1068 msafter display: 0 ms at 1085 msafter display: 0 ms at 1101 msafter display: 0 ms at 1118 msafter display: 0 ms at 1135 msafter display: 0 ms at 1151 msafter display: 0 ms at 1169 msupdate: 0 ms at 1195 mssyntax: 13 ms at 1195 mscalculate: 19 ms at 1195 mssyntax: 5 ms at 1209 mscursor info: 0 ms at 1214 mscolor map: 0 ms at 1214 msview: 106 ms at 1214 msafter display: 1 ms at 1327 msthe edited program compiled againhazel-jit: the run compiled: 159 ms at 292 msthe worker: its runworker: request decoded: 2 ms at 175 msworker: request decoded: 1 ms at 177 msworker: encode ack: 1 ms at 178 msworker: post ack: 0 ms at 179 msworker: request composed: 33 ms at 179 msworker: reuse plan: 15 ms at 212 msworker: slices: 131 ms at 212 msworker: encode reuse plan: 7 ms at 220 msworker: post reuse plan: 0 ms at 227 msworker: encode stream: 0 ms at 343 msworker: post stream: 0 ms at 343 msworker: slices: 31 ms at 343 msworker: slices: 31 ms at 374 msworker: slices: 30 ms at 405 msworker: slices: 31 ms at 440 msworker: slices: 30 ms at 475 msworker: slices: 30 ms at 510 msworker: slices: 31 ms at 543 msworker: slices: 31 ms at 579 msworker: slices: 30 ms at 615 msworker: slices: 30 ms at 649 msworker: slices: 31 ms at 683 msworker: slices: 110 ms at 717 msworker: slices: 30 ms at 831 msworker: slices: 30 ms at 865 msworker: slices: 30 ms at 899 msworker: slices: 75 ms at 933 msworker: make result: 0 ms at 1105 msworker: post result: 0 ms at 1169 msthe answer: encoded, decodedworker message decoded: 0 ms at 456 msworker message decoded: 1 ms at 459 msworker message decoded: 0 ms at 461 msworker: encode result: 64 ms at 1105 msworker message decoded: 23 ms at 1171 msthe slider and the picture redrawn, 286 msthe worker's answer, 1328 ms16.7 ms
The quickest of the steps whose picture came from the compiled run, from the page's own timeline and the worker's (Util.BenchMarks), each block a measured piece of work at the time it started; the worker's pieces are on its own thread, the rest on the page's. The green line is one 60 fps frame. Run 42554043524.

So the compiled run removes the wait for the worker, but not the work the page does for any edit: a slider's new model is a change to the program's text, and the page treats it as one, statics and the whole slide's view included. For a step that changes one livelit's model, under the conditions ^report(46) listed (compiling the run), none of that is needed: the compiled run's answers say what every livelit shows.

The steps back#

On the two steps back to a slider's starting value (neck 30 to 28, arms 65 to 55), the compiled run answered as quickly, but in run 42551267058 only 57 to 62 livelits were drawn from its answers, against 208 on the steps away, and the picture waited for the worker: 1.66 to 1.69 s. The cause was in how the page tracks a livelit's pending model; fixed in a51dc778dd, all four steps now draw the picture at the first redraw, 286 to 386 ms after the step (42554043524).

The page keeps, for a livelit just changed, an optimistic entry: the model it was given, until the worker's run shows it, with the list of program texts its own commits made. On a slide the run samples no livelit view, so the entry's convergence test, which compares the view, never passes, and the entry outlives its step. After neck 28 to 30 its list was 28, 30; the step back added 28 again. The match took the first 28, earlier than the state it had matched last, for an undo, and dropped the entry while the page was drawing: the livelits drawn before the slider had taken the run's answers, and every one after it, the picture among them, fell back to the old samples. The match now looks at or after the state matched last first, and only then earlier, so an undo is still seen; and the answers last until the worker's sample of the changed model catches up with it, not as long as the entry.

What the Node numbers assumed#

The compiled run first never ran in the app: the page compiled the slide's program, but none of its livelit uses had a model to hand a new value to (0 of 53 on the Witch). A slide's program, as the page holds it, has no livelit views in it. Statics folds a livelit's view into the run only for a use that is probed, and a slide is elaborated with only its cells' own probes (Program.probe_ids, then DefStatics.calc_auto); the page draws each livelit by running its view itself. ^report(45)'s measurement in Node elaborated the slide with every use probed (hazel jit --views), so its 2.3 to 2.5 ms ran a program the page never holds. The same assumption is in ^report(46)'s speculation (compiling the run), which says the run samples every livelit's view today; on these slides it does not.

A slider's use, as a slide's program holds it (elaborated):

match Drawing.^slider("neck", 0, 60).expand {
| Functional(f) => f(28)
| Macro(_) => ?
}

As the compiled run folds it, before compiling (in Hazel, with the two calls of hazel-jit's runtime written in):

let %model = $R.param(the 28's id, 28) in
let _ = $R.sample(the use's id,
          Drawing.^slider("neck", 0, 60).view(%model)) in
match Drawing.^slider("neck", 0, 60).expand {
| Functional(f) => f(%model)
| Macro(_) => ?
}

The fold is the one Statics makes for a probed use (UserLivelit.instrument_view), made by the compiled run on its own copy of the program, so the worker's run is unchanged. A macro livelit, such as the Witch's ^picture, is expanded when the program is elaborated and holds no definition to call view on; the page now notes each use's definition as it draws it, and the fold uses that. With both, every livelit use on every polygon slide is folded in (53 of 53 on the Witch).

The same drawings#

Every polygon slide was loaded with compiled views on and off, events run on each, and every livelit's drawing compared: 0 differences on 6 slides. On the Witch, 525 livelit drawings came from the compiled run's answers. The counts are the page's own (globalThis.hazelJit), over the load and the events the check runs on each slide, with compiled views on:

slidelivelitsevents the compiled run answeredlivelits drawn from its answersviews compiled (drawn by the page)views on the interpreter
Polygons1150180
Polygon Viewer10020
Full Body435425617
Witch535525687
Hands175148265
Scenes106114239

"Views compiled" are the page's own runs of a livelit's compiled view, as before; "views on the interpreter" are views whose model hazel-jit cannot carry into JS yet (a model holding a splice's code, the ^picture's among them), which the compiled run now computes inside the run instead.

What it costs#

After each step the program's text has a new literal, so the page compiles the program again: 143 to 184 ms on the page's thread, once a step, between the first redraw and the worker's answer. The new program differs from the old only in the literal that is already the run's parameter, so the old compiled code, given the new value, is the new program's. Keeping it would remove this cost.

Five runs#

Five pushes to the trial branch, each with its run of the Firefox check: from "never ran" to every livelit's view in the compiled run, and the picture at the first redraw on every step.

commitwhat it changedFirefox runthe Witch's uses folded inwhat the run showed
1d445a24ccthe app wired: at a livelit's event, the slide's compiled run is called with the new model425475788250 of 53never used: the page compiled the program after each edit, but no event ran it, and the reason went only to the console
06a3880c01every event, answer and reason not to run counted in the page, for the check to read425484269100 of 53on every slide and event: none of the program's livelit uses has a model parameter
932fbdcc63each livelit use's view folded into the compiled run, as Statics folds a probed use's4254994197752 of 53the run fires at every event, 1 to 7 ms; 52 of the Witch's 53 uses folded; the picture, a macro livelit, not
6d71c427bfa macro livelit's view folded too, from the definition the page notes as it draws the use4255126705853 of 53all 53 folded; the picture drawn from the compiled run at the page's first redraw in 2 of 4 steps, the steps away from a slider's starting value
a51dc778dda step back to a slider's starting value no longer taken for an undo; the answers kept until the worker's sample of the model catches up4255404352453 of 53all 53 folded; the picture drawn from the compiled run at the page's first redraw in 4 of 4 steps

What next#

  1. Keep the compiled run's answers until the worker's answer for the same step arrives, whatever value the slider returns to (the steps back). Done 11-08 night, a51dc778dd.
  2. Do not compile again when only a parameter's literal changed: 143 to 184 ms a step on the page's thread (what it costs).
  3. For a step that changes only livelit models, skip the page's whole-program work: statics, and the whole slide's view, most of the 286 to 386 ms before the first redraw; draw only the livelits whose answers changed.
  4. Do not run the worker, or do not redraw from its answer, when the compiled run has answered: it spends 0.74 to 1.01 s and the page then draws every view again, to the same picture.
  5. Make hazel jit --views elaborate a slide as the page does, so its numbers in Node measure the program the app compiles.
  6. Put a dated note in ^report(45) and ^report(46) where they assume the run samples every view.

How this was put together#