Hazel reports · ^report(57) · hazel-jit · 2026-11-18, revised 2026-11-18 09:58 MST · work in progress · after reports 052, 054 and 056
What the Livelits PR Compiles
Matthew Hammer asked, on 2026-11-18, to what extent hazelgrove/hazel#2819 uses hazel-jit: for livelit views only, or for anything else. This is the answer, read from the pull request's code, with a section for each use, written for his conversation with Cyrus Omar today about what makes livelits responsive, and how it reaches dev; the team's next mergeathon is tomorrow, 2026-11-19.
Outline#
- In short: in the app, hazel-jit serves livelits only, four ways; outside it, a command, tests and a browser check.
- In the app: livelit views, livelit updates, the slide's whole run, and the worker's request held.
- Outside the app: the command line, a measuring page, the tests, the Firefox check.
- What #2819 does not have: everything since the morning of 2026-11-09, the step budget and the consistency check among it.
- What makes livelits responsive: the ten changes
^report(52)ranked, which of them are hazel-jit, and which #2819 holds. - Reaching dev:
^report(52)'s nine increments, brought up to date; for tomorrow's mergeathon; and what to decide with Cyrus.
In short#
In the running app, #2819 uses hazel-jit only for livelits, but for more than their views: their updates, and each slide's whole run, which it compiles only to draw livelits sooner. The program's result, probes, tests and the stepper always come from the interpreter. Outside the app it adds a command, tests and a browser check. Read from the pull request's code at c419e01559 (2026-11-09), behind the Compiled views setting, which is on by default there.
- Livelit views. A livelit's view function is compiled and run on the page's own thread with the livelit's model, and its answer drawn straight into the page, never made into a Hazel value; handlers that take a payload run compiled too.
- Livelit updates. The definition's update function is compiled too: on an action, a new model comes back as a diff against the old one; any other answer goes to the interpreter.
- The slide's whole run. The slide's program is compiled once, each livelit's model a parameter; at a livelit's event the whole program runs as JavaScript with the new model, and every livelit is drawn from that run before the worker's run returns. Its answer is used only to draw livelits.
- The worker waits. When the compiled run has answered an event, the page holds its request to the interpreter for 400 ms, so a drag costs the worker one run, after its last step.
Outside the app: ./hazel jit FILE.hz to compile a file, check it against the interpreter, and count what it does not compile; a page that times values carried into JavaScript; the HazelJit tests; and the Firefox check that drives the slides and times them. Not in #2819: all the work since its head on the morning of 11-09, which is on the prototype branch (build 50, hazelgrove/hazel#2817).
In the app#
All four uses sit behind one setting, Compiled views (jit_views, on by default on #2819), and each falls back to what the page did before hazel-jit when it meets something it does not compile. The setting sets HazelJitValue.enabled; turned off, nothing is compiled, and every livelit is drawn through the interpreter's run, as on dev.
1. Livelit views, compiled#
A livelit's view, a Hazel function from its model to HTML, is compiled once per definition and called on the page's own thread whenever the livelit is drawn: 3.0 ms a render of the Witch's picture against 87 ms through the interpreter. (^report(46), in Firefox; ^report(52), ingredient A4.)
- How.
LivelitProjasksHazelJitValue.view_of_deffor the definition's compiled view, andcall_viewruns it on the model, carried into JavaScript.HazelJitDOM.godraws the answer, the JavaScript values the compiled code made, straight into the page's virtual DOM: every view command (Pure, Bind, whose continuation is the compiled function, Editor, EvalSplice, ResultView) and every element, attribute and handler, asHazelDOMdraws them from a Hazel value. - Handlers. A handler crosses into Hazel only when its event comes: a click's message is carried back then; a handler that takes a payload is the compiled function, called on the payload in JavaScript, and only its answer, the message, carried back.
- When it gives up. A form hazel-jit does not compile, or an answer that is not well formed, raises
Unsupported, and the page draws through Hazel as before. So do apps whose messages transform the program's syntax. - Measured. The Witch's picture: 87 ms a render on the interpreter, 3.0 ms compiled (
^report(46)). A Polygons render in Node: 14.1 ms to 0.38 (^report(45)). In a drag, a livelit drawn from JavaScript takes about 1 ms, against 4.6 with nothing compiled (builds 30 to 39,^report(52)). - Code. 606 lines added outside the compiler, and the compiler's own 4,328 at that time (
^report(52)'s count).
2. Livelit updates, compiled#
The definition's update, compiled, runs on the model and the action; when it answers Pure(new model), the new model comes back as a diff against the one it was given, so every part it did not change stays the very same Hazel value. Any other command goes to the interpreter. (^ticket(715), ^report(45)'s second step; HazelJitValue.call_update, called from LivelitProj.)
- Why a diff. Carrying a whole answer back costs time in its size. The compiled code builds a new model functionally, so a part it did not touch is the same JavaScript object, and the diff stops there without looking inside; the patch keeps the old Hazel value for it.
- When it gives up. A command other than
Pure, or a diff that does not fit the model's type, is an error, and the update runs on the interpreter as before. - Measured. Not on its own in
^report(45)to^report(52), which timed slider steps and drags; a slider's step reaches the model through the compiled run (below) more than through the update.
3. The slide's whole run, compiled#
This is what makes a slider's step show in about 20 ms: the slide's program, compiled once with each livelit use's model as a parameter, answers a livelit's event in 2 to 3 ms as JavaScript, and every livelit draws from that answer before the worker's run comes back. (^ticket(722), ^report(52)'s ingredients A2 and B3; HazelJitRun.)
- How. The page tells
HazelJitRunthe program it draws livelits from (note_program, fromProjectorView); it is compiled soon after, or at the first event that needs it. At an event (step), the program runs with the new model given to its parameter, no new code, and each livelit's view answer is kept for the page to draw straight from JavaScript. - Compiled once. A new program is compared with the compiled one with the models left out (
erase); while only models change, the compiled function is kept. Comparing takes about 1 ms a step (build 17); compiling again took 126 to 141 ms (build 8). - When it gives up. A form hazel-jit does not compile becomes a stub that throws if the run reaches it (
HazelJit.survey); then, or on any other failure, there are no answers, and the page draws from the run's samples as before. - Measured. A step's picture 1.33 to 1.71 s on build 3, 208 to 236 ms on build 5 when the run was compiled (
^report(49)); in Node, a slider's step 684 ms on the interpreter, 2.3 to 2.5 ms compiled (^report(45)). - What rides on it. Two changes that need the compiled run to have answered: draw first, edit after the paint (A3: the step's picture 152 to 195 ms on build 11, 19 to 24 on build 12), and a drag redraws only what changed (A5: a 3-second drag 9.8 fps on build 5, 57.6 on build 12).
- Its answer is only for livelits. The result panel, probes and tests come from the interpreter's run in the worker, as always.
4. The worker's request, held#
When the compiled run has just answered a livelit's event, the page holds the request it would send the worker for 400 ms, replacing it by any newer one, so a drag costs the worker one run, after its last step, not one a step. (^report(50)'s fourth step; WorkerClient.hold_if_answered, asking HazelJitRun.take_answered.)
- Why. The page's livelits are already drawn from the compiled run; the worker's answer would only draw them again, to the same picture, and the page would spend each step decoding it.
- The cost. Probes, tests and every other cell still get the worker's answer, later: 400 ms after the last step, plus the worker's run.
Outside the app#
Four tools, none of which a user of the app meets.
- The command line:
./hazel jit FILE.hzcompiles a file, with--checkruns it both ways and compares, and counts by reason the forms it would not compile (HazelJit.survey;src/CLI/Cli.re). - A measuring page: the data experiment times carrying a value into JavaScript (
DataExperiment,HazelJitValue.to_js). - The tests:
test/Test_HazelJit.re, each compiled program run both ways and its answer compared with the interpreter's. - The Firefox check:
.github/workflows/jit.ymlandscripts/jit_slides.pydrive six slides in Firefox on GitHub's machines and time each slider step and drag, compiled views on and off.^report(52)calls it the ruler.
What #2819 does not have#
#2819's head is the prototype's build 12 and two commits, from the morning of 2026-11-09; everything since, 123 commits to build 50, is on the prototype branch only, including the step budget that answers Cyrus's concern about compiled code on the page's thread.
| Build | Commit | Date | What it is |
|---|---|---|---|
| 12 | d9d63c13af | 2026-11-09 | the prototype when #2819 was cut: a drag's frames reuse each editor's decorations and probes' views; #2819's head is this and two commits (samples as data turned off, a formatting pass) |
| 38 | 19ecb75694 | 2026-11-10 | ^report(52)'s measurements: a step's picture 20 to 31 ms after the click, a drag 55.7 fps |
| 49 | 0e56bdbd0a | 2026-11-17 | ^report(54)'s: the meeting's changes merged, all of CI green |
| 50 | 55e4757a4b | 2026-11-18 | today's prototype, trial/694-view-jit (hazelgrove/hazel#2817): build 49 and the slides' builtins |
- Page work that needs no compiler (
^report(52)'s B1, B2, B4, B5, builds 13 to 41): livelits kept across an edit, the outline on its own, the autosave without a redraw, the probe row. Together about 0.4 to 0.8 s off the page's work after a step, as each was measured when it landed. - Correctness (
^report(54), builds 46 to 50): the consistency check in CI, every evaluator test program run both ways; Int and Nat exact past 253; SInt at 32 bits with overflow an error; divide by zero and other invalid operations stopping, for the interpreter's answer; the rules that keep holes, type holes and type errors with the interpreter; the step budget; the slides' builtins. - The step budget (
^ticket(763)) in particular: on #2819, a compiled view or run on the page's thread has no limit, so a Hazel function that never ends, or ends late, would hold the page until JavaScript's stack overflows or it ends. On the prototype, a run past 50 ms or 50 million calls stops, and the interpreter answers (^report(56), Programs that never end). - Mixed mode, the step toward compiling any complete function, not only livelits' code: in the tests only, on the prototype.
The prototype's preview is build.hazel.org/trial/694-view-jit/; ^report(51) and ^report(55) point there instead of #2819.
What makes livelits responsive#
Two changes did most of it: the worker's answer sent without what the page does not read, which needs no compiler, and the slide's whole run compiled. Of the ten changes ^report(52) ranked, five are hazel-jit or ride on it, and five need no compiler at all; #2819 holds the five, and the answer's trimming, but none of the page work. ^report(52) measured each when it landed, on the Witch slide in Firefox, one run a build; the two groups measure different things and are not added.
| # | Change | Compiler? | Measured when it landed (^report(52)) | In #2819 |
|---|---|---|---|---|
| What a user waits for: a step's picture, a drag's frame | ||||
| A1 | Send the worker's answer without what the page does not read | no compiler | 2.84 to 4.81 s off a step (builds 2, 3); the answer 590 KB to 198 KB (build 20) | partly (builds 2 and 3, not 20) |
| A2 | Compile the slide's whole run, each livelit's model a parameter | hazel-jit | 1.09 to 1.50 s off a step (builds 4, 5): a step's picture 1.33 to 1.71 s, then 208 to 236 ms | yes (builds 4 and 5; not 18 (the first step like the others)) |
| A3 | Draw first; make the edit after the paint | needs the compiled run | 133 to 171 ms off a step (build 12): 152 to 195 ms, then 19 to 24 | yes (build 12) |
| A4 | Compile each livelit's view | hazel-jit | 84 ms off each render of the Witch's picture: 87 ms to 3.0 | yes (before build 1) |
| A5 | A drag redraws only what changed | needs the compiled run | 80 to 85 ms off each frame of a drag: 9.8 fps (build 5) to 57.6 (build 12) | yes (builds 6, 7, 8 and 12) |
| The page's work after the picture, which can make the next frame late | ||||
| B1 | Keep the livelits a change did not touch | no compiler | 190 to 400 ms off the page's work after a step (builds 15 to 39) | no (builds 15 to 39) |
| B2 | Build the outline on its own, and only what changed | no compiler | 128 to 201 ms off a step (builds 13 to 41) | no (builds 13 to 41) |
| B3 | Compile the run once; compare only what changed | hazel-jit | 125 to 140 ms off a step: compiling again 126 to 141 ms (build 8), comparing 1 ms (build 17) | partly (builds 9 and 10, not 17) |
| B4 | Save without a redraw, printing only what changed | no compiler | 77 to 96 ms off a step (builds 16, 23) | no (builds 16 and 23) |
| B5 | Draw the picture's probe row without rewriting its value | no compiler | 38 to 85 ms off each answer (builds 14, 26) | no (builds 14 and 26) |
Today, on build 50 (the Firefox check, run 44319161252), with compiled views on: a 3-second drag of the Witch's neck slider at 54.3 frames a second, the page's view 6.5 ms a frame (about 154 fps); a step's first redraw 27 to 30 ms after the click (89 ms for the slide's first step), hazel-jit's own run 5 to 11 ms of it. With compiled views off, the same drag runs at 42.0 frames a second, the view 15.4 ms a frame (about 65 fps), and its longest frame is 133 ms against 34.
Reaching dev#
User-defined livelits are not on dev yet, and #2819 is 1,680 commits ahead of dev, the whole livelits stack with hazel-jit on it; so hazel-jit's livelit uses reach dev after the livelits do, in ^report(52)'s increments, carrying the correctness work done since. Livelits going into dev was settled with Cyrus on 2026-11-05; how, in what pieces and in what order with hazelgrove/hazel#2469, is still open. dev has LivelitProj today, for the built-in livelits; the user-defined ones, whose views and runs hazel-jit compiles, come with hazelgrove/hazel#2597's stack.
| Order | Increment | What it holds | Needs first | Where it is now |
|---|---|---|---|---|
| 0 | The ruler | The Firefox check that drives the slides and times each step and drag, the page's timeline of marks, the worker's answer weighed by part. Nothing a user sees. | nothing | On the prototype; on #2819 as it was on 11-09. |
| 1 | The worker's answer, smaller | Ingredient A1: the worker and its messages only. Helps dev as much as livelits. | nothing | On the prototype; #2819 has its first two parts. |
| 2 | Page work every edit pays | B2, B4, B5: the outline on its own, the autosave without a redraw, the probe row. Each its own small PR. | the outline and autosave: livelits; the probe row: dev | On the prototype only. |
| 3 | Livelits kept | B1: a livelit's view, shape and applied definition kept, keyed on what it reads; one cache a PR, each with a test that it gives the same view. | livelits | On the prototype only. |
| 4 | The compiler | hazel-jit itself, a module at a time, and now its correctness (^report(54)): exact Int and Nat, SInt at 32 bits, invalid operations stopping, the rules for holes, type holes and type errors, and the consistency check in CI. Nothing a user sees. | nothing | On the prototype, build 50; its CI checks 313 evaluator programs and 129 slides both ways. |
| 5 | Compiled views | A4, with the step budget (^ticket(763)), since it runs compiled code on the page's thread. | 4, livelits | #2819 has the views, without the budget; the prototype has both. |
| 6 | The run compiled in the page | A2 and B3: the slide's run compiled once, called at a slider's event, kept while only models change. | 4, 5 | #2819 has it as of 11-09; the prototype has it whole. |
| 7 | Draw first, edit after the paint | A3. | 6 | In both. |
| 8 | The drag fast path | A5: four changes, each its own PR. | 6 | In both. |
^report(53) explains why the prototype is to be redone by hand rather than merged: its 120 commits came with few tests of their own, and some only fixed the one before. ^report(52)'s plan holds, with two updates. The compiler's increment now has its correctness work and the consistency check in CI to carry, which make it reviewable: every program it compiles is checked against the interpreter on every push. And the step budget should land with the first increment that runs compiled code on the page's thread, the views.
For tomorrow's mergeathon#
What could be opened or merged on 2026-11-19 without waiting on livelits.
- The two interpreter fixes, already open, CI green, waiting on a review: hazelgrove/hazel#2828 (SInt at 32 bits, overflow an error) and hazelgrove/hazel#2825 (modulo by zero crashed the interpreter).
- The ruler (increment 0): the Firefox check and the page's timeline of marks, which change nothing a user sees and let every later increment be measured.
- The worker's answer, smaller (increment 1, ingredient A1): the worker and its messages only, helping dev as much as livelits.
- The compiler, a module at a time (increment 4), with its tests and the consistency check in CI, and nothing a user sees: it can land before livelits, since it compiles any closed program and checks itself against the interpreter.
- #2819: closed, or marked as superseded, with a pointer to the preview and to these increments, so no one reviews a stale branch.
To decide with Cyrus#
- Which comes first for responsive livelits? Our lean: the page work that needs no compiler (A1, B1, B2, B4, B5) lands with or right after the livelits, as it helps every edit; then compiled views; then the compiled run. The run is what makes a step show in 20 ms; views alone make drags and redraws fast.
- Compiled views on dev: on by default, or behind a setting that starts off? Our lean: off at first, on once the consistency check and the step budget have run a while in CI.
- Is the step budget a condition for compiled code on the page's thread? Our lean: yes; it is Cyrus's concern of 11-13, and #2819 has none.
- What becomes of #2819? Our lean: close it in favor of the increments, keeping the preview build for trying.
- The compiler before livelits? Our lean: yes, as a library with its check in CI and nothing a user sees, so its review is not tied to the livelits' landing.
How this was put together#
Written on 2026-11-18 from #2819's code at c419e01559 (each file that calls into hazel-jit, read for what it calls: LivelitProj, HazelJitDOM, HazelJitRun, WorkerClient, ProjectorView, Settings, Cli, DataExperiment), its ancestry checked against each numbered build's commit, and from ^report(45) to ^report(56), whose measurements are quoted with their builds. Today's numbers are build 50's Firefox check (run 44319161252). Nothing new was measured for this report.
The data#
- 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 in057/data/.