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#
- 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.
- 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.
- 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.
- 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.
- The same drawings: on all 6 polygon slides, compiled and not, no differences.
- What it costs: the edited program compiled again after every step, 143 to 184 ms on the page's thread.
- Five runs: what each change did, in order.
- 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.
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 compiled | the step | the compiled run, each event (ms) | compiled again after (ms) | the slider redrawn (ms) | the picture (ms) |
|---|---|---|---|---|---|
| on | neck 28 to 30 | 9, 2 | 149 | 386 | 386 |
| on | neck 30 to 28 | 8, 3 | 159 | 286 | 286 |
| on | arms (up / down) 55 to 65 | 21, 2 | 143 | 289 | 289 |
| on | arms (up / down) 65 to 55 | 9, 2 | 184 | 381 | 381 |
| off | neck 28 to 30 | - | - | 428 | 1744 |
| off | neck 30 to 28 | - | - | 285 | 1388 |
| off | arms (up / down) 55 to 65 | - | - | 288 | 1622 |
| off | arms (up / down) 65 to 55 | - | - | 252 | 1352 |
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.
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:
| slide | livelits | events the compiled run answered | livelits drawn from its answers | views compiled (drawn by the page) | views on the interpreter |
|---|---|---|---|---|---|
| Polygons | 1 | 15 | 0 | 18 | 0 |
| Polygon Viewer | 1 | 0 | 0 | 2 | 0 |
| Full Body | 43 | 5 | 425 | 61 | 7 |
| Witch | 53 | 5 | 525 | 68 | 7 |
| Hands | 17 | 5 | 148 | 26 | 5 |
| Scenes | 10 | 6 | 114 | 23 | 9 |
"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.
| commit | what it changed | Firefox run | the Witch's uses folded in | what the run showed |
|---|---|---|---|---|
| 1d445a24cc | the app wired: at a livelit's event, the slide's compiled run is called with the new model | 42547578825 | 0 of 53 | never used: the page compiled the program after each edit, but no event ran it, and the reason went only to the console |
| 06a3880c01 | every event, answer and reason not to run counted in the page, for the check to read | 42548426910 | 0 of 53 | on every slide and event: none of the program's livelit uses has a model parameter |
| 932fbdcc63 | each livelit use's view folded into the compiled run, as Statics folds a probed use's | 42549941977 | 52 of 53 | the run fires at every event, 1 to 7 ms; 52 of the Witch's 53 uses folded; the picture, a macro livelit, not |
| 6d71c427bf | a macro livelit's view folded too, from the definition the page notes as it draws the use | 42551267058 | 53 of 53 | all 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 |
| a51dc778dd | a 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 up | 42554043524 | 53 of 53 | all 53 folded; the picture drawn from the compiled run at the page's first redraw in 4 of 4 steps |
What next#
- 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.
- 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).
- 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.
- 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.
- Make
hazel jit --viewselaborate a slide as the page does, so its numbers in Node measure the program the app compiles. - Put a dated note in
^report(45)and^report(46)where they assume the run samples every view.
How this was put together#
- The build: a release build of
trial/694-view-jit(hazelgrove/hazel, the livelits line with hazel-jit), at the five commits in five runs; the numbers in the sections above are from the last run that fired, 42554043524 at a51dc778dd. - The check:
scripts/jit_slides.pyin Firefox on GitHub's machines (.github/workflows/jit.yml, ubuntu-latest): each polygon slide loaded with compiled views on and off, its events run and timed, the drawings compared; on the Witch, four slider steps each way (neck 28 to 30 and back, arms 55 to 65 and back) on a fresh load, each timed from the slider's input event by watching the page for the slider's and the picture's elements to change, with the page's own timeline and the worker's (Util.BenchMarks) for where the time went. One run of four steps each way: say so beside any comparison; GitHub's machines vary from run to run (the steps with nothing compiled took 1.15 to 1.66 s in one run and 1.90 to 2.24 s in the next), so compare within a run. - The counts are the page's own (
HazelJitValue.count, read asglobalThis.hazelJit), including each reason the compiled run was not used, added for this work after the first run showed nothing. - The code:
HazelJitRun(the run compiled with the livelits' models as parameters, the fold, and the step), its call inLivelitProjat a livelit's event and in its view, andProjectorViewtelling it the program; hazel-jit's parameters and samples inHazelJit. - The numbers, for programs too: every table in this report, and what its numbers measure, is also in this page as JSON, in its
<script type="application/json" id="report-data">element, so a reader or an agent that fetches the page alone has the dataset. The same, with any raw files that survive, is in049/data/.