Hazel reports · ^report(54) · hazel-jit · 2026-11-16, revised 2026-11-24 20:58 MST · work in progress · after ^report(52)

Same Answers as the Interpreter

hazel-jit compiles a livelit's view, and a slide's whole run, from Hazel to JavaScript, so that a slider's step can show in the picture within a frame (^report(50) to ^report(52)). On Friday 2026-11-13 Matthew Hammer and Cyrus Omar met about its next steps. The main one: what the compiled code computes must be what Hazel's interpreter computes, and CI must check it. Here is the plan from that meeting, change by change, and where each change stands. It also covers what it would take to run any piece of a Hazel program this way, not only livelit views, and the direction chosen: a mixed mode, where the interpreter calls compiled functions. This report is revised as the work goes on.

Outline#

  1. The plan: the meeting's items, as tickets, and how far each has come.
  2. What hazel-jit is, for a reader new to it: what it compiles, where it runs, and what happens to what it does not compile.
  3. The same answers, checked in CI: every evaluator test program also runs compiled, and a difference fails the build.
  4. The same programs, timed: the evaluator's programs, each run in the interpreter and compiled, timed; and a larger program, the astrology oracle, 170 times as fast compiled.
  5. Exact integers: Int and Nat as the interpreter has them, past 253.
  6. Divide by zero and other invalid operations: the compiled run stops, and the interpreter's run answers.
  7. Overflow: SInt had three widths; now 32 bits everywhere, and overflow an error.
  8. What stays with the interpreter: holes, type holes, programs with type errors, and the stepper's functions, explained.
  9. The other limits, one at a time: what the compiler did not handle, ranked by how often the tests meet it, and what is done.
  10. A step budget: Cyrus's concern, that a compiled function that never ends would freeze the page.
  11. What it all costs: the Witch slide, build by build.
  12. Found along the way: an interpreter crash on modulo by zero, fixed on a PR, and a cost of undeclared result types.
  13. Beyond livelits: compiling any piece of a program, what today's design assumes, what is new in general, mixed mode, the direction chosen, step counts and probes as the interpreter's, and compiling ahead of time for older phones.
  14. Lists as JavaScript arrays, and holes: arrays measured against today’s cells and a hybrid of the two; holes in lists, terms with holes, the order to build them in, and where hazel-jit lives now.
  15. Records the page’s way: a record held as a page’s object crosses for nothing and builds about 12 times as fast; five decisions, for Matthew (^ticket(847)); decision 1 chosen: A, records as objects, with field reads in place, takes 0.63 of today’s time as the games play; decisions 2 to 5 done as leaned.
  16. A sequence beside List: a treap over array views inserts anywhere in about a microsecond at every size up to a million, and takes a page’s array for nothing; a walk costs about what cells cost (^ticket(846)).
  17. What a closure keeps: whether dev trims a value’s environments to what the value uses (it does not), where that was tried, what trimming would take, and what the jit already does.
  18. Questions for the team: seventeen open design questions, each with our lean, for the team's meeting of 2026-11-17, two of them met by the astrology oracle this morning.
  19. What next, with next steps for Matthew and others, and how this was put together.

The plan#

Of the meeting's seven changes, six are done on the hazel-jit branch and pass CI, overflow among them: SInt is 32 bits everywhere, each result checked. One is under way: the limits, where four of the evaluator's 313 programs still meet one, all four ill-typed tests left so on purpose, and probes are not begun. Each became a ticket on the work dashboard. Three more tickets came out of the work itself: a crash in the interpreter, now fixed on a PR to dev; a cost in how Hazel checks types at run time; and the oracles, slow on an older phone, now compiled ahead of time. A last ticket is the direction chosen after the meeting, mixed mode. What the team could decide is gathered in questions for the team.

The plan, ticket by ticket, on 2026-11-24each dot a stage reached; for ticket 764 the last stage is a PR to dev, not the branchdesignedwrittenCI greenon the branch756 the same answers, checked in CI757 Int and Nat exact758 overflow: a stuck term759 divide by zero: a stuck term760 holes, the stepper: the interpreter's761 the other limits, one at a time763 a step budget764 found: modulo by zero crashed762 found: undeclared result types765 found: slow on an older phone766 next: mixed mode767 next: steps and probes
Tickets 756 to 763 are the meeting's items; 762, 764 and 765 were found on the way, and 766 is the direction chosen after the meeting; 767 is the meeting's answer on steps and probes. For 765 the last stage is the oracles' pages running compiled code. Green: done on trial/694-view-jit (hazelgrove/hazel#2817, the hazel-jit prototype); amber: in progress; grey: waiting on a decision or not begun; blue: on a PR to dev. Not a build of the app: a status chart.

Matthew's summary of the meeting, as he wrote it on 2026-11-15:

And Cyrus's concern, which Matthew passed on separately the same day: "We need a way to limit compiled hazel functions that diverge --- we need a step limit. esp if we continue to optimize by including certain jit-compiled hazel functions into the main thread"

TicketThe changeWhere it stands
^ticket(756)Consistency with the interpreter, checked in CIOn build 49: every evaluator test program also runs compiled, and any difference fails CI; so do the slides' own programs (129: 15 compile, all agree); each program timed both ways.done
^ticket(757)Int and Nat exact, as the interpreter'sOn the branch: a JS number while it is a safe integer, a BigInt past that. Measured on the Witch.done
^ticket(758)Overflow stops at a stuck termOn the branch: SInt is 32 bits everywhere, each result checked in the interpreter and hazel-jit (decided 11-16). The interpreter's half is on a PR to dev, hazelgrove/hazel#2828: CI green, its tests reaching 96% of the changed lines; waiting on review.done
^ticket(759)Divide by zero stops at a stuck termOn the branch: the compiled run stops, and the interpreter makes the stuck term.done
^ticket(760)Holes and the stepper stay with the interpreterOn the branch, with two rules the sweep found: no program with type errors, and no type hole. Left: a check in the browser.done
^ticket(761)The other limits, one at a timeOn the branch: 20 builtins, partial application, mutual recursion, undefined, tuple extension and labels, strings in graphemes, reverse application. On their own branch, CI green 11-17: an unlabeled entry, from_lvs, a module member that is an expression, a value in a recursive definition; four programs of 313 still meet a limit, all four ill-typed tests. Probes not begun.in progress
^ticket(763)A step budget for compiled codeOn the branch: 50 ms or 50M calls a run, then the interpreter. Left: a cheaper counter.done
^ticket(764)Found: modulo by zero crashed the interpreterFixed on a PR to dev, hazelgrove/hazel#2825, waiting for review.on a PR
^ticket(762)Found: an undeclared result type costs a step 5 to 7 timesMeasured in Hazel's interpreter; the cause is where the ascriptions go. The fix is not begun.waiting
^ticket(765)Found: the oracles were slow on an older phone; compiled ahead of timeThe I Ching and the Tarot run compiled by default (hazeljs-oracles 0.0.13), each checked against hazeljs over thousands of answers: on the phone, ready in 0.8 s, not 3.7 s. Astrology too since 0.0.16 (11-18): a chart in about 1 ms, not 1.4 s, the same as hazeljs on 40 charts. Left: the compiler inside hazeljs.done
^ticket(766)Chosen after the meeting: mixed modeA first step is written, on its own branch, CI green 11-17: the interpreter runs the program and calls its functions with declared types, top-level and in modules, compiled, as builtins. The Petri net rule 22 times as fast, the I Ching's 4.in progress
^ticket(767)Asked 11-13: the interpreter's step counts in compiled code, then probesDesigned: yes to both, with care for casts and a check in CI (below). The interpreter's counts for 57 small programs measured; the counter in compiled code not begun.in progress

All of the done changes are on trial/694-view-jit, the hazel-jit prototype branch (hazelgrove/hazel#2817), as build 50 since 2026-11-18. Build 49 (2026-11-17) merged that morning's branches (the last limits, mixed mode, the timing, the slides' check, the step calibration), with all of CI green on it (static checks, fast checks and full tests, CI run 44137711359) and the slides' browser check too (run 44137800916; the builds). Build 50 adds the slides' builtins, a fast-forward of their branch once all of its CI was green (CI run 44211080673); the prototype's own CI then passed on build 50 too (CI run 44319161267; the full tests in 94.5 minutes, close to their 100), and so did the slides' browser check (run 44319161252). Each was written on its own branch, passed CI there, and was brought together with the others; CI passed again on the whole, and so did the slides. None is on dev: ^report(53) explains why the prototype is to be redone by hand in small steps.

What hazel-jit is#

hazel-jit translates an elaborated Hazel program to the text of a JavaScript function, and the page runs that function on its own thread at a livelit's event, to draw the livelits before the interpreter's answer comes back. Hazel's interpreter, in a web worker, still runs every program, and its answer is still the program's result: the probes, the tests and the result panel come from it. So far hazel-jit has been a measurement of how fast compiled Hazel could be (a step of the Witch's slider in 2 to 3 ms, ^report(50)). The meeting's point is that it must also be correct, because whatever it draws, a user reads as what Hazel computed.

A form the compiler does not handle raises an error with its reason, and the page then waits for the interpreter's run, as it did before hazel-jit. So a limit costs speed, never correctness. A compiled run that stops part way (an invalid operation, undefined, or the step budget) is handled the same way. These fallbacks are what keep hazel-jit's answers the same as the interpreter's: where the two would differ, hazel-jit gives no answer and the interpreter's is shown.

The same answers, checked in CI#

Every one of the evaluator's 313 test programs now also goes through hazel-jit in CI. 260 compile, and each gives the interpreter's answer, apart from 27 known ill-typed tests, and those the page never compiles. A new difference fails the build. (^ticket(756).)

Build 49: the 313 evaluator test programs, run both ways0 differ, 0 threw: every compiled program gave the interpreter's answer, or is a known ill-typed test2332749agreed (233)not a value: ill-typed, known (27)not compiled, by rule (49)not compiled, a limit (4)
Build 49 (0e56bdbd0a), the fast checks' sweep (CI run 44137711359). Each of the evaluator's test programs also goes to hazel-jit: compiled and run in JavaScript, its answer compared with the interpreter's. "Not a value": the interpreter stops at a failed run-time type check in an ill-typed test (4 : String, ...), which compiled code, its types erased, would run past; the page never compiles such a program (^ticket(760)). By rule: holes, type holes, and the tests' unbound names. A limit: a form hazel-jit does not compile yet (^ticket(761)).

The check is a sweep in the evaluator's tests: each test hands its program to hazel-jit, runs the JavaScript, and compares the value with the interpreter's: numbers exactly (floats within a relative 10-9), lists, tuples, labels and constructors by structure, and a function only as being a function. A compiled run that stopped at an invalid operation agrees with an interpreter result stuck at the same error (below). The 27 ill-typed tests are listed by name, and anything else that parts from the interpreter fails its test. The end of each run prints a report in CI's log: how many were compiled, how many agreed, and why the rest were not compiled.

The first sweep, on 2026-11-15 (the full tests), had 316 programs: 237 compiled, 207 agreed, 30 ill-typed, and none differed. It found the rule that programs with type errors stay with the interpreter (below). Merging the six branches found one more parting, with no static error: a value passed through a written type hole to a function that takes another type. That led to the rule that a type hole is a hole. The 49 programs not compiled by rule, and the 4 not compiled for a limit, are these:

Not compiled becauseProgramsRule or limit
a hole (a label that is a hole among them)15rule
a type hole10rule
a free variable (the tests' own unbound names: y 13, s2 6, x 2, b2 2, a 1)24rule
a fixpoint over a pattern that is not a name or a tuple of names (fix _ : (), fix (_ : Bool), fix 0; ill-typed tests)3a limit (^ticket(761))
a fixpoint over (), a tuple of no names, whose body is not a function (fix () -> []; an ill-typed test; corrected 11-18, once CI named it)1a limit (^ticket(761))

What is left: the slides' own programs, which the sweep does not see. They are checked only by the Firefox run on GitHub's machines, which compares the pictures, not the values.

The same programs, timed#

Run again and again, the 233 evaluator programs that compile and give the interpreter's value took the interpreter 32 ms a run in all, and compiled code 0.18 ms. The median program is 222 times as fast compiled (34 µs against 0.22 µs), and every one is faster, from 2.3 to 3,624 times; the 70 that take the interpreter 0.1 ms or more, a median 321 times. Run once, compiling included, as a page that compiles before its first run would, the median program is 1.2 times as fast, and 87 of the 233 are slower: programs of a few microseconds, where compiling is the cost. Matthew asked for these on 2026-11-17: the evaluator's test programs, timed in the interpreter and in hazel-jit.

The evaluator's 233 programs, a run's time each wayeach dot a program, each time a run's, over its repeats: across, the interpreter; up, the compiled JS0.01 µs0.01 µs0.1 µs0.1 µs0.001 ms0.001 ms0.01 ms0.01 ms0.1 ms0.1 ms1 ms1 ms10 ms10 msas fast100 times as fast10,000 timesthe interpreter, a runcompiled JS, a run
Build 49 (0e56bdbd0a, CI run 44137711359, the fast checks, Node on GitHub's machines). Each program's interpreter runs repeated until they added to 20 ms (10 to 1000 times), and its compiled JS's until they added to 5 ms; each dot is a run's time, the total over the repeats. Below the line marked "as fast", compiled code was faster. Not a build of the app.

How each was timed: in CI, in the same Node process as the tests, as the consistency check ran. Most of these programs take the interpreter well under a millisecond, too near the timer's grain for one run to say much, so each is run again and again (Matthew: "can we repeat the work 100 or 1000 times to get a multi ms number in the interpreter?"). The interpreter's runs repeat until they add to 20 ms, at least 10 times and at most 1000. The compiled JavaScript's repeat until they add to 5 ms, at most 100,000 times. The times are a run's, the total over the repeats. Both are warm then: the interpreter has seen the program before, and so has the JavaScript engine. The first runs are kept too, since a page meets those: the interpreter's as the test ran it, hazel-jit's compile to JavaScript's text, and the JavaScript parsed and run once.

Program (the evaluator's test)The interpreter, a runCompiled JS, a runAs fast, timesFirst runs: the interpreterhazel-jit's compileThe JS parsed and run
[(index=true, `A`=60, `B`=30, `C`=0), (index=false, `A...5.43 ms ×1019.6 µs ×25527715.5 ms0.36 ms3.13 ms
[(1, 3), (2, 4)] == zip([1, 2], [3, 4])3.59 ms ×1480.99 µs ×50523,6240.13 ms72.5 µs71.8 µs
[1, 1, 3, 4, 5] == sort(fun (x, y) -> if x == y then Eq else ...1.89 ms ×204.7 µs ×10554001.09 ms0.20 ms0.16 ms
[5, 4, 3, 1, 1] == sort(fun (x, y) -> if x == y then Eq else ...1.71 ms ×183.3 µs ×14995121.30 ms0.22 ms0.11 ms
[1, 2, 3] == unique([1, 2, 2, 3, 1, 3])0.99 ms ×301.8 µs ×27225381.50 ms0.17 ms98.7 µs
[1, 2] == sort(fun (x, y) -> if x == y then Eq else (if x < y...0.84 ms ×281.1 µs ×45377631.10 ms0.34 ms42.2 µs
[1, 2, 3] == sort(fun (x, y) -> if x == y then Eq else (if x ...0.71 ms ×355.3 µs ×11591360.66 ms0.30 ms0.12 ms
[(1, [1, 3]), (0, [2, 4])] == group_on_key([1, 2, 3, 4], fun ...0.53 ms ×511.0 µs ×48905221.16 ms0.13 ms89.2 µs
[5, 3] == type T=String in let map = typfun a ->typfun b -> f...0.44 ms ×650.85 µs ×75715120.54 ms91.8 µs56.5 µs
[2, 4] == filter([1, 2, 3, 4], fun x -> int_mod(x, 2) == 0)0.39 ms ×780.43 µs ×116409070.34 ms93.1 µs0.18 ms
[1, 3] == filteri([1, 2, 3, 4], fun (i, x) -> int_mod(i, 2) =...0.37 ms ×670.64 µs ×118165711.63 ms0.14 ms60.9 µs
[3, 2, 1] == reverse([1, 2, 3])0.34 ms ×1020.56 µs ×89536170.28 ms0.13 ms48.2 µs

The slides' own programs, timed the same way on build 49: of the 129 programs under hazel-programs, 21 have a static error and stay with the interpreter, as do those with a hole (27), a type hole (25) or a test (25); 10 call to_lvs and 4 int_plus, builtins hazel-jit lacks; the 15 that compile and give the interpreter's value took the interpreter 8.4 ms a run in all and compiled code 0.026 ms, the median program 269 times as fast.

Program (hazel-programs/)The interpreter, a runCompiled JS, a runAs fast, timesFirst runs: the interpreterThe JS parsed and run
docs/reference/polymorphism.hz2.16 ms ×120.88 µs ×57792,4574.12 ms0.13 ms
docs/livelits/either/either-typed.hz1.90 ms ×161.7 µs ×29471,1211.78 ms0.41 ms
docs/livelits/splices-mvp.hz1.27 ms ×275.6 µs ×8872250.85 ms0.62 ms
docs/livelits/either/either-unknown.hz0.59 ms ×562.0 µs ×25122960.43 ms92.1 µs
docs/livelits/result-view.hz0.47 ms ×451.7 µs ×28752690.54 ms0.11 ms
docs/livelits/splices-in-text.hz0.44 ms ×611.2 µs ×40373530.40 ms0.47 ms
docs/livelits/splice-row.hz0.41 ms ×387.4 µs ×672540.94 ms0.10 ms
docs/livelits/hygiene/generated-binders.hz0.39 ms ×701.3 µs ×37132920.42 ms82.5 µs
docs/livelits/lockable-cell.hz0.27 ms ×561.3 µs ×39222041.60 ms66.2 µs
docs/livelits/hygiene/capture.hz0.25 ms ×920.82 µs ×61083110.27 ms0.46 ms
docs/livelits/hygiene/abs.hz0.19 ms ×101.6 µs ×46051180.32 ms0.59 ms
docs/livelits/advanced/javascript.hz22.9 µs ×3460.05 µs ×1000005100.14 ms7.5 µs
docs/livelits/expansion-errors/errors-about.hz5.5 µs ×10000.04 µs ×10000012766.8 µs7.6 µs
docs/livelits/either/either-about.hz4.3 µs ×3870.04 µs ×1000009960.6 µs11.6 µs
docs/livelits/hygiene/about.hz3.2 µs ×10000.04 µs ×1000007357.1 µs6.1 µs

These are the evaluator's own tests, which are small: most take the interpreter well under a millisecond. The Witch slide is the larger case (what it all costs, and ^report(50) to ^report(52)), and mixed mode's timings are larger programs again (the first step, built).

A larger program: the astrology oracle#

The astrology oracle's rules, eleven modules of floating-point code, compile whole and give the interpreter's answer, 170 times as fast: a reading in 2.6 ms compiled against 437 ms interpreted. The evaluator's programs above are small, most under a millisecond. This one is the Hazel of hazeljs-oracles' astrology page (its astrology/rules at fbfc59f, about 30 kB: the Sun, the Moon and the planets from Meeus's and Schlyter's series, the chart's angles, the aspects and the reading's words), joined as hazeljs joins it and asked for one reading, a birth and a day.

PhaseTimeRuns
Parsed (FastParse, as hazeljs parses)592 ms1
Elaborated196 ms1
The interpreter's run, one reading437 ms1
hazel-jit's compile, the whole program13 ms1
The compiled JavaScript's run (79 kB of it)2.57 ms3

Build 49 with the test added (trial/768-astrology-timed, 81945a4d4c, CI run 44191280236, the fast checks, Node on GitHub's machines). One run each, so these are one sample, not a distribution: the compiled run's three runs are the first and two more, and the interpreter's run is its first. The two answers were compared value by value and agree. Mixed mode's measure of the same program is in the full tests, not yet back.

Getting these numbers took five CI runs, each past its time limit. The tests' own parser reads text by inserting it, as typing would, which is slow for a 30 kB program, so the test now parses with FastParse. Three readings, each run three times, plus mixed mode, were too much for the 20 minutes the quick tests had left. The fifth run wrote each phase to a file as it ended, which CI prints after the tests whatever happens. That file shows the test itself finishing in under 2 s, and the quick tests still going past their limit. Found 2026-11-18: with build 50 merged in, whose consistency check runs a program that already takes 20 ms only once more instead of ten times, the same branch's quick tests pass in 12.7 minutes (the fast checks, 14.7; CI run 44320263066), the astrology test giving the same answer, 144 times as fast compiled there. So build 49's timing rule was the cause, as guessed.

The astrology page now casts compiled by default (hazeljs-oracles 0.0.16, 2026-11-18, ^ticket(768); Matthew: "It seems like we should, if possible"), as the I Ching and the Tarot have since 0.0.13 (compiled ahead of time). A test on trial/768-astrology-aot (build 50 and the astrology tests) prints the rules compiled whole, their answer the function Reading.reading, and the oracles' tools/make-compiled.py wraps them, 101 kB with the runtime. In Node, over 40 charts, the app's own and then births, days and places drawn from 1900 to 2099: a chart that hazeljs builds and casts in a median 1,436 ms is cast compiled in 0.85 ms (0.36 ms warm), with the same words and every number within a relative 10-10. In the browser pane, a first cast took 13 ms, without loading hazeljs at all.

Exact integers#

Int and Nat are now exact in compiled code, as the interpreter's are: an integer is a JavaScript number while it is a safe integer (up to 253 − 1), and a BigInt past that. (^ticket(757).) The interpreter's Int and Nat are arbitrary-precision integers (Jane Street's Bigint), and hazel-jit had made them JavaScript numbers, which round past 253: 253 + 1 came out as 253.

Every integer operation normalizes its result back to a number when it fits, so two equal integers are always the same value, and === still compares them. Division rounds toward zero, as the interpreter's does, and stays exact where Math.trunc(a / b) would round. Where plain BigInt everywhere cost a 4.1 times slower fib(25), a 1.5 times slower list walk, and 9.6 times slower model updates, this mix costs 1.6 times, nothing measurable, and 3.7 times (Node, against plain numbers; not a build of the app). On the Witch slide it costs nothing measurable (below). SInt, Hazel's fixed-width integer, stays a JavaScript number: its width is the overflow question.

Divide by zero and other invalid operations#

Where the interpreter stops at an error (dividing by zero, a negative power, int_of_string of something not a number), the compiled run now stops too, and the page shows the interpreter's run, which holds the stuck term with its error. (^ticket(759).) Before, 7 / 0 compiled to Infinity.

The stuck term is the same as the interpreter's by construction, since it is the interpreter's. The alternative, making the stuck term in JavaScript and evaluating around it as the interpreter does, would be a much larger piece of work and is not needed for the answers to agree. Writing the tests for this found a crash in the interpreter itself, on modulo by zero (below).

Overflow#

Decided on 2026-11-16, Matthew Hammer: an SInt has 32 bits everywhere, and a result past them is an error, a stuck term, as a divide by zero is. Done in the interpreter and in hazel-jit, and on the hazel-jit branch since build 48, all of CI passing. (^ticket(758).) Until now SInt overflowed three different ways, depending on how Hazel ran. In the browser, Hazel runs under js_of_ocaml, where an OCaml int has 32 bits, and SInt wrapped silently. A native build of Hazel has OCaml's 63-bit int. hazel-jit had a JavaScript number (checked through hazeljs 0.0.6, which runs Hazel as the browser does):

ProgramThe browser's interpreter (32 bits, wraps)A native build (OCaml's 63-bit int)hazel-jit (a JS number)
use SInt in 2147483647 + 1-214748364821474836482147483648
use SInt in 65536 * 65536042949672964294967296
use SInt in 1000000 * 1000000-72737996810000000000001000000000000
use SInt in 2 ** 31-214748364821474836482147483648

Now each of these stops, in all three, at a new error, IntegerOverflow ("Error: Integer overflow (an SInt has 32 bits)"). Every SInt operation (sum, difference, product, power, negation, and the one quotient too big, the least SInt divided by −1) checks its result against [−231, 231 − 1]. The interpreter computes the result as a floating-point number first: exact for any two 32-bit operands' sum, and past 253 surely out of range. So the answer no longer depends on the width of the int the interpreter runs on. A value made into an SInt from an Int, a Nat or a Float that does not fit stops at the existing IntegerTooBig, natively too. hazel-jit makes the same checks and stops its run there, for the interpreter's. Seven tests check both agree, values at the edges of 32 bits included (3c9fb4d9ed). Changing the interpreter changes the language, so the interpreter's half is its own PR to dev, hazelgrove/hazel#2828, with tests of its own. Its CI is green; it waits on a review.

Int and Nat cannot overflow (above), and Float follows IEEE 754 in all three.

What stays with the interpreter#

By rule, not as a limit, hazel-jit leaves to the interpreter: any program with a hole (now including a type hole, ? in a type), any program with type errors, and anything the stepper shows. (^ticket(760).) Each is written down at the head of the compiler's source, HazelJit.re.

Holes. Empty holes, multiholes, dynamic error holes and invalid text were already not compiled: the interpreter evaluates around a hole, and its indeterminate result is the point of a hole. Type holes are new, from the merge's sweep. A value passed through ? to a function taking [Int] fails a run-time check when it is a list of floats, and the interpreter shows the failed check. Compiled code has no types to check, and a float and an int are both a JavaScript number, so it cannot tell. No slide writes a type hole. Type errors. The first sweep's 30 ill-typed tests (4 : String, 1 + (4 : String), ...) are programs where the interpreter stops at a failed run-time check. Now the page compiles no program with static errors. Checked on the six slides of the Firefox check, neither rule stopped any slide from compiling. The four slides with compiled runs kept them (a count of 28 against 30 reflects when a run was timed, not a program that stopped compiling):

SlideLivelits drawn from the compiled run, build 45With the type-error rule (45 + 760)Build 47, with the type-hole ruleBuild 48
Full Body30303030
Hands30302828
Scenes36363636
Witch30283030

The stepper's functions, which Matthew asked to have explained. Hazel's stepper shows a program's evaluation one step at a time. Four forms of expression tell it which steps to show: hide P in e (skip the steps matching pattern P), eval P in e (take them without stopping), pause P in e (stop at them), and debug P in e. These are "stepper functions" in the sense Cyrus meant. They only mean something to a run that takes steps, so hazel-jit does not compile them (the reason is "a stepper filter"). Beyond the filters, nothing the stepper shows is drawn from compiled code. The stepper evaluates by the interpreter's own steps, and a livelit inside a probe drawer's stepper, drawn over one of its samples, is now drawn by the interpreter, never from a compiled run's answer (in the code and its tests; not yet checked in a browser).

The other limits, one at a time#

Ranked by the first sweep, the limits most often met were missing builtins, partial application, recursion over more than one name, undefined, and other forms of term. The first three are on the hazel-jit branch, undefined passes CI on its own branch, the other forms pass CI too, and probes are not begun. (^ticket(761).)

A step budget#

Every compiled function now counts its calls and every 16,384 calls reads the clock. A run past its budget (50 ms or 50 million calls) stops, and the interpreter's run answers. (^ticket(763).) Cyrus's concern is that compiled code runs on the page's own thread, so a Hazel function that never ends would freeze the page. The interpreter has a 20-second timer and a limit of 100 million transitions.

Endless recursion turned out to be the smaller risk: it overflows JavaScript's stack in about a millisecond, and that error is caught like any other. The real risk is a run that ends, but late (fib(45)), and the clock catches that. In Node the counter costs 11 to 26%, and 20 to 33% with the clock (not a build of the app). On the Witch it costs nothing measurable in one run (below), well inside a frame. A cheaper counter, at only the calls that can recur, is the next step.

What it all costs#

On the Witch slide, the changes together are not measurably slower than build 45: over a 3 s drag the page's view took 5.4 to 7.2 ms a frame from build 46 to build 50 (6.5 ms, about 154 fps, on build 50), against build 45's 5.8 (about 172 fps); hazel-jit's own run is 1.1 to 1.7 ms of it. One run each. The spread between single runs (5.4 to 7.3 ms) is as large as any difference, so the numbers show no cost and no gain. On all six slides of the check, build 49 drew the same pictures as the interpreter, with no errors (run 44137800916: 6 slides, 0 differences). Every build stays far inside the 16.7 ms of a 60 fps frame. The fps assumes that updating the state is free: it is what the view alone allows.

The Witch: the page's view a frame over a 3 s drag, by buildthe view's time with its frame rate as if updating were free; the darker bar, hazel-jit's compiled run within it; one run each16.7 ms: a 60 fps frame45 · the base5.8 ms (about 172 fps); run 1.3 ms45 + 757 · exact integers6.6 ms (about 152 fps); run 1.7 ms45 + 763 · a step budget7.3 ms (about 137 fps); run 1.5 ms45 + 760 · no type errors7.0 ms (about 143 fps); run 1.5 ms46 · the six together5.4 ms (about 185 fps); run 1.1 ms47 · a type hole is a hole7.2 ms (about 139 fps); run 1.6 ms48 · the limits, SInt, label keys6.1 ms (about 164 fps); run 1.6 ms49 · this morning's branches6.8 ms (about 147 fps); run 1.5 ms50 · the slides' builtins6.5 ms (about 154 fps); run 1.7 ms
Builds 45 to 48, the Witch slide in Firefox on GitHub's machines (jit.yml), dragging the neck slider for 3 s with compiled views on: the page's view per frame, and hazel-jit's compiled run per frame within it. One run each: the spread between them (5.4 to 7.3 ms) is as large as any difference, so these say no build is measurably slower than build 45, not which is fastest.

The builds are numbered as in ^report(50) to ^report(52). Builds 45 + 757, 45 + 763 and 45 + 760 are each build 45 with one change, measured on its own. Build 46 is the six merged; build 47 adds the type-hole rule; build 48 adds the rest of the limits done since, SInt at 32 bits, and labels named length; build 49 adds the last limits, mixed mode's first step, the timing, the slides' check and the step calibration; build 50 adds the slides' builtins, and is what trial/694-view-jit holds now.

BuildCommitRunWhenWhat it addsView a frame (drag)Compiled run a frameCompiled run at a stepDrawn from the compiled run
45 · the basefc1103900d4288867826911-10^report(52)'s last build: the slide's whole run compiled, on trial/694-view-jit.5.8 ms (about 172 fps)1.3 ms4 to 8 ms30
45 + 757 · exact integersb908b4ed2e4376344344811-15Int and Nat exact (^ticket(757)), on build 45 and ^ticket(756)'s first step.6.6 ms (about 152 fps)1.7 ms4 to 9 ms30
45 + 763 · a step budgetb81b39f8d44376343984211-15A counter in every compiled function, and a budget around each run (^ticket(763)), on build 45.7.3 ms (about 137 fps)1.5 ms5 to 10 ms30
45 + 760 · no type errors1b89af31c54376579716611-15No program with type errors compiled (^ticket(760)), on build 45.7.0 ms (about 143 fps)1.5 ms3 to 6 ms28
46 · the six together59f28470c34379287875411-15Tickets 756, 757, 759, 760, 761 and 763 merged on build 45.5.4 ms (about 185 fps)1.1 ms5 to 10 ms30
47 · a type hole is a holef4f969588b4389863657711-16Build 46 and the type-hole rule (^ticket(760)).7.2 ms (about 139 fps)1.6 ms4 to 10 ms30
48 · the limits, SInt, label keys30a131a0464394942030911-16Build 47 and undefined, tuple extension and the label builtins, strings in graphemes, reverse application (761), SInt at 32 bits (758), and labels named length (765); trial/694-view-jit since 11-16.6.1 ms (about 164 fps)1.6 ms5 to 11 ms30
49 · this morning's branches0e56bdbd0a4413780091611-17Build 48 and the last limits (761), mixed mode's first step (766), the timing and the slides' check (756), the step calibration (767); trial/694-view-jit since 11-17, all of CI green.6.8 ms (about 147 fps)1.5 ms4 to 12 ms30
50 · the slides' builtins55e4757a4b4431916125211-18Build 49 and operators passed as functions, to_lvs, a projection through a list as the interpreter's, and the checks' trail (761, 756); trial/694-view-jit since 11-18.6.5 ms (about 154 fps)1.7 ms5 to 11 ms30

Found along the way#

Modulo by zero crashed Hazel's interpreter, on dev too; the fix is a PR to dev, hazelgrove/hazel#2825, waiting for review. (^ticket(764).) int_mod, sint_mod, nat_mod and float_mod answered a zero divisor with an error naming a builtin mod that does not exist, so evaluating it raised an exception instead of showing "Error: Divide by Zero". This dates from at least 2025-07-02. Renaming was not enough: the error's inside was then stepped again, and the error was lost. So the fix also makes a builtin's error final, as an operator's already is. CI passes with it.

A Hazel function that declares what it takes but not what it returns costs 5 to 7 times as much a step at run time, in the interpreter. (^ticket(762).) It was measured in a Tarot deck written in Hazel: a step of take cost 0.36 ms with only its argument types, and 0.07 ms with its whole type. Declaring every type made a deal 3.7 times faster. The cause is not unknown types, but where the ascriptions (the run-time type checks) land: on each case arm's result, in each copy of the body, rather than once around it. This is the interpreter's cost, not hazel-jit's, and it is the kind of check Matthew Keenan asked about in ^report(53). The next step is to count the checks per call.

Beyond livelits#

Most of hazel-jit's limits come from one assumption: it compiles a whole program that is closed, finished and well typed, and its answer is only a preview, with the interpreter's run as the real answer. Running any piece of a program in JavaScript breaks each part of that. The direction chosen is a mixed mode: the interpreter keeps running the program and calls compiled functions as it calls a builtin. Matthew Hammer asked on 2026-11-16 what it would take to apply hazel-jit to any fragment of elaborated Hazel, and which of its assumptions stand in the way. Of three ways to go, he chose the third: "I like the mixed mode idea a lot."

Mixed mode: the interpreter calls compiled functions, as it calls a builtina design sketch, not built yetHazel's interpreter, in the workerevaluates the program, around its holes, with its probeslet rule : (Net, Int) -> Net = ...complete, typed: compiledlet view = fun n -> ... ? ...a hole: the interpreter'slet total = fun xs -> ... probe ...a probe: the interpreter's... rule(net, 2) ...a callCompiled functions (JS)rulecall each other directly;each call under the step budgetthe argument, to JS oncethe answer, by its declared typea stop (the budget, an invalidoperation, a value that willnot convert): the Hazelfunction runs instead
Not a build of the app: a design sketch. The interpreter keeps running the program, with its holes and probes; a function whose body is complete, has its whole type declared and holds no probe is compiled once, and the interpreter calls it as it calls a builtin. Any stop falls back for that one call, to the same Hazel function.

What today's design assumes#

  1. The program is closed. Its only free variables are builtins, and a closure carrying its own environment is not compiled. A slide's run starts from nothing, so this has not mattered. A piece from inside a program has free variables bound to the interpreter's values, closures among them: those must be converted on the way in, and an interpreter closure must either be compiled too or be called back from JavaScript.
  2. The compiled answer is a preview. The page draws from it, and the interpreter's answer, arriving later, is the program's result. If compiled code gives the result itself, every remaining difference is a wrong answer, and the consistency check becomes a gate.
  3. Falling back is all or nothing, and costs nothing extra, since the interpreter runs anyway. For a piece of a program, falling back means running it twice, partly in JavaScript and then in the interpreter. That is safe only because evaluation has no side effects.
  4. The answer's type is known. Converting an answer back needs its type: a Float 1.0 and an Int 1 are the same JavaScript number, and without a type a tuple's labels are guessed from its properties. A view's answer is always Html.
  5. The inputs are small. Views draw small models, so recursion stays shallow. JavaScript has no tail calls and a stack of thousands to tens of thousands of calls, depending on the browser, where the interpreter keeps its stack on the heap. A List.map over 100,000 elements works in the interpreter and overflows compiled; today that falls back, correct but slow.
  6. Three shortcuts are for livelits only: a livelit's model is a parameter, so a slider step does not recompile; each view's answer is collected by its projector; and Html goes straight to the page's DOM without becoming Hazel terms. In general, every edit changes the code, so it is compiled again, and new code starts cold in the JavaScript engine. Compiling is quick (the Witch's largest livelit definition, 62,000 nodes: 6 ms to translate, 9 ms for the browser to parse), but what to cache by, and what to make a parameter, come back as questions.
  7. The program is finished. Holes, type holes and type errors go to the interpreter by rule (above). A program being edited usually has holes, so compiled code helps only its complete parts. That argues for compiling pieces rather than whole programs.

What is new in the general case#

  1. Divergence and long runs. The step budget bounds a freeze. But its units are calls and time, not the interpreter's steps, so compiled code may finish where the interpreter would time out, or the reverse. If the same answers include the same timeouts, the limit needs a definition in the language that both count the same way. A piece of a program that draws nothing belongs in the worker, where a long run freezes nothing.
  2. The boundary costs. Converting values in and out builds Hazel terms and makes new ids. ^report(45) found a livelit's render about 40 times slower with that trip in and out than compiled alone. Small pieces that cross often lose most of the gain, so pieces must be large, or values must stay in JavaScript between calls.
  3. What the interpreter records: probes, the stepper's steps, traces, test results, and the ids that tie a value to the code that made it. Compiled code records none of them. A piece holding a probe or a test, or shown in the stepper, stays with the interpreter.
  4. Evaluating around holes, Hazel's central feature: a program with holes still runs, and its result holds the holes. Compiled code cannot; it stops.
  5. Run-time type checks. Where a value passes through the unknown type ?, the interpreter checks it as the program runs; compiled code has no types to check with. Values entering a compiled piece typed ? would need checking on the way in.
  6. Every builtin twice. Each of Hazel's builtins written in OCaml has a twin written by hand in JavaScript, and a general compiler meets them all. Looking for this report found one that differed: string_length (above, now fixed).
  7. Security. Compiled code runs through new Function with the page's full access. For livelits, that is slides we wrote; for any piece of any program, including one opened from a shared link, a bug in how the compiler escapes text would let a program run its own script in the page. A page whose security policy forbids eval cannot run it at all.
  8. Two implementations to maintain. Every new language feature must either compile or fall back, and the consistency check must cover it.

Three ways to go#

  1. Whole closed programs, in the worker, with the interpreter as the fallback: close to what we have, without the livelit shortcuts, and unable to freeze the page.
  2. A fragment interface: compile a closed function whose free variables are typed parameters, convert its inputs once, and keep its values in JavaScript.
  3. Mixed mode, the one chosen: the interpreter calls compiled functions as it calls builtins, for functions that are complete, free of probes and worth compiling. The first two are steps toward it.

Mixed mode#

Mixed mode keeps the interpreter in charge of the program, so holes, probes and the stepper work as they do now, and gives its complete functions compiled speed. A first step is built (^ticket(766), below). The sketch it follows:

The first step, built on 2026-11-17

Mixed mode's first step is on its own branch, trial/766-mixed, beside the prototype: the interpreter runs the program, and calls each top-level function and module member with its whole type declared as compiled JavaScript. On 0e56bdbd0a (CI run 44137711359, green), the consistency check found 6 evaluator programs with a function to compile (7 functions), and all 6 gave the interpreter's answer; 29 other functions were left to the interpreter because their whole type is not declared, which bears on the question of which functions to compile. Measured on larger programs (below): a recursion compiled whole runs hundreds of times as fast; the Petri net rule 7 times (22 times on the branch's own run, where the interpreter took 463 ms rather than 121: these are single runs, and noisy); the I Ching 5 times, since only 13 of its functions compile so far (its readings call other modules' members, Lines.becomes, which the rewrite does not see yet); and a one-line function called 500 times from interpreted code is slower than not compiling it, each call's crossing costing more than its work.

ProgramThe interpreter aloneMixedRewrite and compile, onceFunctions compiledCalls compiledFell back
fib(16), all compiled72.6 ms0.1 ms0.5 ms110
the Petri net rule of ^report(43), whole types declared, 100 events from an interpreted loop120.8 ms16.8 ms5.5 ms121120
the I Ching of hazeljs-oracles, 200 readings from an interpreted loop1117.5 ms235.0 ms3.7 ms1378000
500 calls of a one-line function (sq) from an interpreted loop22.4 ms27.9 ms0.2 ms15000

Build 49 (0e56bdbd0a, CI run 44137711359, Node on GitHub's machines), each program once after a first run, not repeated as the evaluator's programs are; the same answer both ways checked. Not a build of the app.

Step counts and probes, as the interpreter's#

Compiled code can count exactly the steps the interpreter takes, in every program it compiles, with care in three places. With those counts it can make the interpreter's own probe samples, with two limits. Nothing found so far makes either impossible: the costs are a little run time, a tie to the interpreter's internals, and the work. This answers Matthew and Cyrus's two questions of 2026-11-13 (^ticket(767)). Not built yet.

What the interpreter counts. Its count goes up by one at every transition, whichever of its 36 kinds: those that interpret the program (a variable looked up, a let bound, a function applied, an operator, a case, a projection) and those that are bookkeeping (a closure wrapped, parentheses removed, a cast). It goes up one more after each pattern match. The count is the same with or without incremental reuse: a reused result adds the steps it took when it was first computed, so that probe samples stay where they were. Each probe sample is stamped with it: the span of steps from its start to its end.

The counts, measured. For 57 small programs, each a construct apart from the last, the interpreter's count is regular enough to read off (^ticket(767)'s calibration, CI run 44131334098). A literal is a step. An operator or a pair of parentheses adds one. A let adds three of its own: binding, its pattern, and completing the closure around its body. Each level of a simple recursion, if n == 0 then 0 else f(n - 1), adds exactly 16 (18, 34, 50, 66 for f(0) to f(3)). A declared Int -> Int adds one cast step to each call. Some counts need the interpreter's bookkeeping to explain: true && false takes 4 and false && true 3. The whole table:

The 57 programs and their counts
ProgramSteps
11
1 + 23
1 + 2 + 35
(1)2
((1))3
-12
!true2
true && false4
false && true3
1.0 +. 2.03
"a" ++ "b"3
let x = 1 in 25
let x = 1 in x5
let x = 1 in x + x7
let x = 1 in let y = 2 in x + y11
let (a, b) = (1, 2) in a7
fun x -> x1
(fun x -> x)(1)7
(fun x -> 1)(2)7
(fun (x, y) -> x + y)(1, 2)11
let f = fun x -> x in f(1)10
let f = fun x -> x in f(f(1))15
((fun x -> fun y -> x + y)(1))(2)15
let f = fun n -> if n == 0 then 0 else f(n - 1) in f(0)18
let f = fun n -> if n == 0 then 0 else f(n - 1) in f(1)34
let f = fun n -> if n == 0 then 0 else f(n - 1) in f(2)50
let f = fun n -> if n == 0 then 0 else f(n - 1) in f(3)66
if true then 1 else 23
if 1 == 1 then 1 else 25
case 1 | 1 => 2 | _ => 3 end5
case 2 | 1 => 2 | _ => 3 end5
case 3 | 1 => 2 | 2 => 3 | _ => 4 end5
(1, 2)4
(1 + 1, 2)6
(a = 1, b = 2)6
(a = 1, b = 2).a8
[1, 2]3
[1 + 1, 2]5
1 :: []4
1 :: 2 :: []6
[1] @ [2]5
Some(1)3
case Some(1) | Some(x) => x | None => 0 end8
string_length("ab")4
string_length("ab") + 16
(1 : Int)3
let f : Int -> Int = fun x -> x in f(1)11
let f = fun x : Int -> x in f(1)10
let f : Int -> Int = fun x -> x in f(f(1))17
let xs : [Int] = [1, 2, 3] in xs8
let f : [Int] -> Int = fun xs -> case xs | [] => 0 | x :: _ => x end in f([1, 2, 3])19
type T = + A + B(Int) in B(1)3
type T = + A + B(Int) in case B(1) | A => 0 | B(n) => n end7
use SInt in 1 + 23
module M = { let x = 1 } in M.x9
let x = 1 in (x, x)8
let f = fun x -> fun y -> x in f(1)(2)15

Why compiled code can match it. hazel-jit translates the program construct by construct and runs it in the same order as the interpreter: arguments first, left to right. Most constructs take a fixed number of steps of their own, apart from their parts: an operator one; a let one, and one for its pattern; an application one, one for its pattern, and the closure's bookkeeping. So the compiler can add, wherever code runs straight through, the steps the interpreter takes there. That is one addition for each straight run of code, about what today's budget counter costs (^ticket(763)). Then the budget and the interpreter's step limit are one number, in one unit.

Where it needs care: the "if not, why not".

  1. Casts carried by functions. A function that has passed through a typed boundary carries the cast with it, and each call through it takes the cast's steps too. How many depends on where the function value has been, not on the code that calls it. Compiled code erases types, so its functions would carry the steps their casts cost, as a number on the JavaScript function.
  2. Casts pushed into code not yet run. A cast around a list or tuple literal is pushed into its parts, and each part then takes steps of its own. This is fixed by the code, so the compiler can follow it, but only by following the interpreter's cast rules exactly.
  3. The rules live in the interpreter's code, not in a specification. There are 36 kinds of step, the extra step after a pattern match, and steps that rebuild a term and evaluate it again under the same id. Some of this is bookkeeping that changes when the interpreter does: a cast through a whole value became one step, for speed, this autumn. So the counts can be held equal only by checking, as values are. The consistency sweep would compare each evaluator test's count with the interpreter's, and a difference would fail CI.

The programs hazel-jit does not compile at all (holes, stepper filters, tests) stay with the interpreter, counts and all. A question for the team: count every step, or only those that interpret the program? Probe samples' spans are in every step today, so to make the same samples compiled code would count them all.

Probes, given the counts. A sample records where (the expression), when (its span of steps), the value, the variables the probe refers to, and the call stack: for each call, the application, the function's name and where it was defined. Compiled code knows the expression at compile time, the steps with the counts above, and the value and variables as JavaScript values. For the call stack it would keep a stack of its own, a frame pushed and popped at each call, paid for only in a program with probes. The way to share the probe machinery rather than write it twice: compiled code emits the same events the interpreter emits as it runs (a span opened, a call entered, a span closed), at the same steps, and the interpreter's own code turns them into samples.

The two limits. First, a sample's value has to come back as a Hazel value, which needs its type at the probe: elaboration has it. A function value comes back only if hazel-jit made it, and not a recursive one. Second, converting each sample's value and variables is the costly part, so it should happen when the page shows a sample, not at every step. The stepper is another matter: counts say how many steps a compiled call took, but the stepper shows the terms in between, and compiled code has none, so it stays the interpreter's.

The way there. (1) The sweep prints each evaluator test's count from the interpreter beside one from compiled code under these rules: how many match exactly, and where they differ. (2) Casts carried by functions. (3) The budget in steps, as one with the interpreter's limit (^ticket(763)). (4) In mixed mode, a compiled call adds its steps to the interpreter's count, so a program's count is the same mixed or not. (5) Probes: the events from compiled code, checked against the probe tests' samples.

Compiled ahead of time, for older phones#

A third use, now a working prototype: compile a hazeljs app's Hazel when the site is built, and ship the JavaScript, so that an older phone loads neither Hazel's interpreter nor its build of the program, and every call runs compiled. On the older Android phone, the I Ching compiled this way is ready to cast at 0.8 s instead of 3.7 s, and a reading takes under a millisecond instead of 86 to 113 ms. It gives hazeljs's answer on all 8,102 checked, in 33 kB instead of 2.8 MB. Since the oracles' 0.0.13 both of them, the I Ching and the Tarot, run compiled by default: the Tarot's 6,400 deals checked are hazeljs's too, and a Celtic Cross takes 0.008 ms instead of 46, in Node. The idea is Matthew Hammer's, on 2026-11-16, after trying the two hazeljs oracles (an I Ching and a Tarot, whose rules are Hazel run by hazeljs in the page) on an older Android phone in Firefox: painfully slow to draw each card or line, and on each key press in the I Ching's question.

What a page like that costs, measured on a laptop:

The editors went first. Since the oracles' 0.0.8, a listing stays text until its button opens the editor, and the I Ching's page, Hazel ready to cast, holds 28 MB. Since 0.0.9, each oracle measures a device's speed and gives a line to compare devices with. The phone's first line, from the I Ching (Firefox 160 on Android, eight cores): Hazel was ready 3.7 s after the page opened, its build of the program 2.9 s of that; a cast took 3 ms by coins and 9 ms by yarrow, a reading 113 ms, and drawing the reading 149 ms to the next frame, since the page asked Hazel for the reading at every redraw. A key press in the question took one frame, 17 ms, with no editor open. The same work in Node on the laptop: the build 600 ms, a cast 0.6 and 1.5 ms, a reading 20 ms, so the phone is about five times slower. In 0.0.10 the I Ching declares every function's whole type (a reading 13 ms on the laptop, the build 480 ms) and asks for the reading once for each set of lines. The phone's line from 0.0.11, still interpreted: the build 2.5 s, a reading 86 ms, and drawing the reading one frame, 17 ms, where it was 149.

Compiling ahead of time would take the rest. hazel-jit would run on the app's Hazel modules when the site is built, and the page would load the compiled JavaScript instead of the library: no build at load, and each call compiled. ^report(50) measured a Petri net rule at 7.19 ms interpreted against 0.011 ms compiled, in Node. Hazel's library and its editor would load only when someone edits the rules, and then the interpreter runs the edited program, as it does now.

The oracles' programs are what hazel-jit compiles best: closed, complete, every function's whole type declared, no probes. So this is the first path above, done before the page loads rather than in it. The prototype, the oracles' 0.0.11, has the four pieces it needs:

Compiling the I Ching found a bug in hazel-jit. A labeled tuple, and a module, is a JavaScript array with each label also a property, and the I Ching's Lines module has a member named length: setting an array's length to a function threw, so every compiled call failed. A label that an array already has a use for (length, __proto__) is now kept under another key, the same everywhere hazel-jit writes or reads one (trial/765-label-keys, 30a131a046).

The phone's speed lines, the same work interpreted and compiled (Firefox 160 on Android, one run each; a 0 is below the phone's timer, which Firefox rounds on purpose):

On the older phone0.0.9, interpreted0.0.11, interpreted0.0.12, compiled
ready to cast3.7 s (Hazel at 0.8 s, then a 2.9 s build)3.7 s (Hazel at 1.0 to 1.2 s, then a 2.5 to 2.8 s build)0.8 s (no library, no build)
a cast by coins3 ms3 to 4 ms0 ms (worst 1)
a cast by yarrow9 ms10 to 11 ms0 ms (worst 8)
a reading113 ms86 to 93 ms0 ms (worst 2)
drawing the reading, to the next frame149 ms17 ms16 ms
a key press in the question17 ms17 ms16 ms

The first two lines the phone sent with ?compiled came back interpreted, and the page did not say why: it fell back to hazeljs on any failure of the compiled file, silently. Since 0.0.12 it says so, in the status line and in the speed line, and with the address as ?compiled=1 the phone ran compiled, with no error.

Lists as JavaScript arrays, and holes#

At the edges, arrays make a page’s list cross into compiled code and back in the same few nanoseconds at every size, where cells cost time in the list’s length (62 ms for a million Ints) and today’s jit, through Hazel’s own values, about seventy times that (4.4 s). Inside compiled code, a hybrid (cells for ::, array segments for literals and a page’s arrays) costs about 8% ahead of time and 4% through the jit on ^report(63)’s seventeen games, all answers the same; plain arrays are the wrong shape inside, since Hazel code walks a list through x :: rest and an array copies its tail at every step. Matthew asked on 2026-11-23 to look at JavaScript arrays for lists, in compiled code and in the interpreter’s evaluated lists, with holes in them; and for hazel-jit to run terms with holes, not only finished programs.

A list of 1,000 Ints, three ways in compiled code: microseconds, log scale1 ns0.1 µs10 µs1 mssum by recursion over x :: restcells: 13.6 µs13.6 µsarrays: 273 µs273 µshybrid: 15.7 µs15.7 µsmap, f(x) :: map(rest)cells: 15.3 µs15.3 µsarrays: 756 µs756 µshybrid: 19.3 µs19.3 µsbuild with an accumulator, then reversecells: 22.9 µs22.9 µsarrays: 1,592 µs1,592 µshybrid: 26.1 µs26.1 µslength (a builtin)cells: 1.4 µs1.4 µsarrays: 0.008 µs0.008 µshybrid: 0.008 µs0.008 µsnth, the middle (a builtin)cells: 0.655 µs0.655 µsarrays: 0.008 µs0.008 µshybrid: 0.008 µs0.008 µsnth, the middle, by recursioncells: 3.4 µs3.4 µsarrays: 222 µs222 µshybrid: 4.4 µs4.4 µsa page's array in and back outcells: 6.1 µs6.1 µsarrays: 0.009 µs0.009 µshybrid: 0.012 µs0.012 µsa page's array in, mapped, back outcells: 22.3 µs22.3 µsarrays: 758 µs758 µshybrid: 21.0 µs21.0 µscells {h, t}, todayarrays, copied by ::cells, a tail an array segment
Not a build of the app: a microbenchmark in Node 22 on the laptop, one run, each time the median of batches (054/drivers/lists-bench.mjs). The workloads are what compiled Hazel code does with a list: recursion through x :: rest, building with ::, the builtins, and a page’s array crossing in and out.
Every workload at 10, 100 and 1,000 elements
elementsworkloadcells (today)arrayshybrid
10sum by recursion over x :: rest0.041 µs0.308 µs0.159 µs
10map, f(x) :: map(rest)0.076 µs0.394 µs0.181 µs
10build with an accumulator, then reverse0.064 µs0.728 µs0.328 µs
10length (a builtin)0.012 µs0.008 µs0.008 µs
10nth, the middle (a builtin)0.008 µs0.008 µs0.008 µs
10nth, the middle, by recursion0.029 µs0.114 µs0.056 µs
10a page's array in and back out0.052 µs0.009 µs0.012 µs
10a page's array in, mapped, back out0.116 µs0.416 µs0.233 µs
100sum by recursion over x :: rest1.1 µs3.7 µs1.4 µs
100map, f(x) :: map(rest)1.4 µs9.3 µs1.7 µs
100build with an accumulator, then reverse2.2 µs17.2 µs2.6 µs
100length (a builtin)0.147 µs0.008 µs0.008 µs
100nth, the middle (a builtin)0.060 µs0.008 µs0.008 µs
100nth, the middle, by recursion0.314 µs1.9 µs0.403 µs
100a page's array in and back out0.569 µs0.009 µs0.012 µs
100a page's array in, mapped, back out2.1 µs10.3 µs2.0 µs
1,000sum by recursion over x :: rest13.6 µs273 µs15.7 µs
1,000map, f(x) :: map(rest)15.3 µs756 µs19.3 µs
1,000build with an accumulator, then reverse22.9 µs1,592 µs26.1 µs
1,000length (a builtin)1.4 µs0.008 µs0.008 µs
1,000nth, the middle (a builtin)0.655 µs0.008 µs0.008 µs
1,000nth, the middle, by recursion3.4 µs222 µs4.4 µs
1,000a page's array in and back out6.1 µs0.009 µs0.012 µs
1,000a page's array in, mapped, back out22.3 µs758 µs21.0 µs

Measured on the games#

On the seventeen games the hybrid, as prototyped, costs about 8% ahead of time and 4% through the jit (geometric means over 45 operations), from a little faster to half again as slow; every answer the same. Go’s search costs most, about half again (1.46 through the jit, 1.58 ahead of time); the astrology chart, made of long list literals, gains about a quarter, and a Mahjong step a little more. Every head and tail of a list now has one more test, a segment’s tail is a new small object where a cell’s tail is already there, and the two shapes meeting in the same hot loop cost the JavaScript engine more than one shape would. What the hybrid saves, constant-time length and nth and a page’s array passed in with no cells made, these games rarely use: their lists are short, and through the jit every value still crosses through Hazel’s own (^report(63)’s crossing), whatever its shape.

The hybrid lists against cells, every game: time with the hybrid ÷ time with cells½ the timethe sametwiceMahjong: a stepjit: 1.06×ahead of time: 0.57×Bricks: the robot's choicejit: 0.98×ahead of time: 0.75×Astrology: a chart (interpreted: the whole pro…jit: 0.76×ahead of time: 0.78×Bricks: a stepjit: 1.09×ahead of time: 0.87×I Ching: a cast by yarrowjit: 1.07×ahead of time: 0.97×I Ching: a cast by coinsjit: 1.05×ahead of time: 0.98×Tarot: a deal, Onejit: 1.06×ahead of time: 0.99×Solitaire: a move madejit: 1.02×ahead of time: 0.99×Downhill: a stepjit: 0.98×ahead of time: 1.00×Light trails: the robot's choice, looking 150jit: 1.11×ahead of time: 1.01×Minesweeper: 16 by 30: a cell openedjit: 1.02×ahead of time: 1.02×Downhill: the robot's choicejit: 0.96×ahead of time: 1.02×Butterfly garden: a stepjit: 0.96×ahead of time: 1.02×Pinball: a boardjit: 1.06×ahead of time: 1.02×Solitaire: a dealjit: 1.06×ahead of time: 1.03×Tarot: a deal, CelticCrossjit: 0.93×ahead of time: 1.05×Snake: a stepjit: 1.04×ahead of time: 1.06×Minesweeper: 9 by 9: a cell openedjit: 0.99×ahead of time: 1.07×Light trails: a stepjit: 1.09×ahead of time: 1.08×Snake: the robot's choice (42 long)jit: 1.10×ahead of time: 1.09×Gnome dig: the robot's choicejit: 1.12×ahead of time: 1.10×Minesweeper: 9 by 9: the hint (a sure move)jit: 0.87×ahead of time: 1.10×Star wave: a stepjit: 1.03×ahead of time: 1.10×Butterfly garden: the robot's choicejit: 1.06×ahead of time: 1.12×Pinball: a stepjit: 1.12×ahead of time: 1.12×Minesweeper: 9 by 9: the mines laidjit: 0.98×ahead of time: 1.13×Minesweeper: 16 by 30: the hint (a sure move)jit: 0.82×ahead of time: 1.13×Gnome dig: a stepjit: 1.00×ahead of time: 1.13×Minesweeper: 16 by 30: the mines laidjit: 1.32×ahead of time: 1.14×Star wave: the robot's choicejit: 1.05×ahead of time: 1.14×Checkers: the movesjit: 1.09×ahead of time: 1.15×Mahjong solitaire: a dealjit: 1.12×ahead of time: 1.17×Checkers: Hazel's move, looking 2 aheadjit: 1.07×ahead of time: 1.18×Checkers: Hazel's move, looking 1 aheadjit: 1.06×ahead of time: 1.18×Tarot: a deal, YearAheadjit: 1.06×ahead of time: 1.18×Solitaire: every legal movejit: 0.97×ahead of time: 1.19×Checkers: Hazel's move, looking 4 aheadjit: 1.05×ahead of time: 1.19×I Ching: a readingjit: 1.04×ahead of time: 1.19×Mahjong: a hand dealtjit: 1.11×ahead of time: 1.20×Go: a move playedjit: 1.13×ahead of time: 1.20×Checkers: Hazel's move, looking 3 aheadjit: 1.06×ahead of time: 1.22×Mahjong solitaire: Hazel's choice of pairjit: 0.76×ahead of time: 1.26×Mahjong: your optionsjit: 1.09×ahead of time: 1.35×Go: the scorejit: 1.37×ahead of time: 1.36×Go: Hazel's choice of movejit: 1.46×ahead of time: 1.58×compiled ahead of timethrough the jit (values crossing through Hazel’s)
Not a build of the app: Node 22 on GitHub’s runners, hazeljs-examples’ node/package-bench.mjs --no-interpreted (run 45258983579). Each game on its own runner, timed with two builds of the package’s hazel-lib.js one after the other: cells (hazeljs at 3f1d825455) and the hybrid (hazeljs-lists at 46b42696f6, the same with hazel-jit-lists merged). One run each, so a ratio within about a tenth of 1 is within what single runs vary.
Every operation, both shapes
operationahead of time, cellsahead of time, hybridratiojit, cellsjit, hybridratio
I Ching: a cast by coins0.117 µs0.115 µs0.985.1 µs5.4 µs1.05
I Ching: a cast by yarrow0.439 µs0.428 µs0.975.3 µs5.7 µs1.07
I Ching: a reading2.8 µs3.3 µs1.1917.7 µs18.4 µs1.04
Tarot: a deal, One0.288 µs0.284 µs0.998.3 µs8.8 µs1.06
Tarot: a deal, CelticCross6.9 µs7.3 µs1.0561.6 µs57.4 µs0.93
Tarot: a deal, YearAhead10.2 µs12.1 µs1.1882.3 µs87.6 µs1.06
Astrology: a chart (interpreted: the whole program built each time)452 µs352 µs0.782,170 µs1,643 µs0.76
Checkers: the moves8.3 µs9.5 µs1.1518.0 µs19.7 µs1.09
Checkers: Hazel's move, looking 1 ahead16.9 µs20.0 µs1.1828.8 µs30.6 µs1.06
Checkers: Hazel's move, looking 2 ahead31.2 µs36.8 µs1.1843.4 µs46.2 µs1.07
Checkers: Hazel's move, looking 3 ahead85.2 µs104 µs1.2298.3 µs104 µs1.06
Checkers: Hazel's move, looking 4 ahead238 µs282 µs1.19257 µs270 µs1.05
Go: a move played4.6 µs5.5 µs1.2061.8 µs69.9 µs1.13
Go: Hazel's choice of move121 µs191 µs1.58154 µs225 µs1.46
Go: the score145 µs198 µs1.36198 µs272 µs1.37
Minesweeper: 9 by 9: the mines laid25.7 µs29.0 µs1.13291 µs286 µs0.98
Minesweeper: 9 by 9: a cell opened9.1 µs9.7 µs1.07385 µs383 µs0.99
Minesweeper: 9 by 9: the hint (a sure move)34.6 µs38.1 µs1.10204 µs178 µs0.87
Minesweeper: 16 by 30: the mines laid152 µs174 µs1.141,778 µs2,351 µs1.32
Minesweeper: 16 by 30: a cell opened39.1 µs39.8 µs1.023,571 µs3,626 µs1.02
Minesweeper: 16 by 30: the hint (a sure move)186 µs210 µs1.131,355 µs1,116 µs0.82
Mahjong: a hand dealt54.0 µs64.5 µs1.20150 µs168 µs1.11
Mahjong: a step3.2 µs1.8 µs0.57114 µs121 µs1.06
Mahjong: your options8.9 µs11.9 µs1.3551.4 µs56.1 µs1.09
Solitaire: a deal16.5 µs17.0 µs1.03196 µs207 µs1.06
Solitaire: every legal move11.2 µs13.3 µs1.19121 µs117 µs0.97
Solitaire: a move made5.4 µs5.3 µs0.99264 µs270 µs1.02
Mahjong solitaire: a deal7,959 µs9,310 µs1.179,681 µs10,872 µs1.12
Mahjong solitaire: Hazel's choice of pair1.0 µs1.3 µs1.26755 µs576 µs0.76
Pinball: a step34.6 µs38.8 µs1.1256.4 µs63.4 µs1.12
Pinball: a board35.2 µs36.0 µs1.02310 µs328 µs1.06
Downhill: a step6.2 µs6.2 µs1.0052.0 µs51.2 µs0.98
Downhill: the robot's choice2.3 µs2.4 µs1.0213.7 µs13.2 µs0.96
Bricks: a step2.3 µs2.0 µs0.8732.7 µs35.5 µs1.09
Bricks: the robot's choice0.388 µs0.289 µs0.7511.4 µs11.2 µs0.98
Snake: a step3.9 µs4.1 µs1.0649.8 µs52.0 µs1.04
Snake: the robot's choice (42 long)161 µs175 µs1.09141 µs156 µs1.10
Light trails: a step7.0 µs7.6 µs1.0848.2 µs52.7 µs1.09
Light trails: the robot's choice, looking 1501,205 µs1,220 µs1.011,100 µs1,226 µs1.11
Star wave: a step17.4 µs19.2 µs1.1097.4 µs101 µs1.03
Star wave: the robot's choice27.6 µs31.6 µs1.1446.7 µs49.3 µs1.05
Butterfly garden: a step16.6 µs16.9 µs1.02129 µs124 µs0.96
Butterfly garden: the robot's choice47.7 µs53.3 µs1.1283.4 µs88.0 µs1.06
Gnome dig: a step26.2 µs29.7 µs1.13177 µs178 µs1.00
Gnome dig: the robot's choice681 µs749 µs1.10596 µs665 µs1.12

A page’s list in and back out, at every size#

A list of Ints passed from a page into hazel-jit’s compiled code and back costs 4 ns as an array and 7 ns as a hybrid segment, at every size from 1 to 1,000,000; as cells it costs 6.2 µs at 1,000 and 62 ms at a million; through Hazel’s own values, as today’s jit does it, 1.2 ms and 4.4 s; through the interpreter, 4.5 ms and 8.9 s. A list of records costs the same, about 0.3 s at a million, as arrays, hybrid or cells, unless the records themselves are held the page’s way. Matthew asked for the round trip from the page’s thread into the compiled code and back, for each way of holding a list, at sizes up to a million, plotted against size, on log and on linear scales.

The function is hazel-jit’s own compiled identity, fun (xs : [Int]) -> xs, compiled by the package and called as a page calls it, on the same thread. For each way, the page’s array goes in as that way holds a list, and comes back as an array: as it is (arrays); copied once each way, in case the page changes its array later; as a segment of the same array (the hybrid), with no copy; converted to cells and back, as the games’ ahead-of-time converters do today; and through Hazel.jit and Hazel.run, which make Hazel’s own values on the way. For scale, one pass over the list in compiled code (a map adding 1, over cells) costs 10.6 µs at 1,000 Ints: cells’ crossing is more than half of a pass, today’s jit crossing more than a hundred passes, and an array’s none.

A list of Ints, into compiled code and back out: log-log1 ns10 ns100 ns1 µs10 µs100 µs1 ms10 ms100 ms1 s10 s1101001,00010,000100,0001,000,000elements in the list (log scale)time, in and back out (log)arrays, no conversion, 1 elements: 2 nsarrays, no conversion, 10 elements: 4 nsarrays, no conversion, 100 elements: 4 nsarrays, no conversion, 1,000 elements: 4 nsarrays, no conversion, 10,000 elements: 4 nsarrays, no conversion, 100,000 elements: 4 nsarrays, no conversion, 1,000,000 elements: 4 nsarrays, no conversionhybrid: cells + array segments, 1 elements: 3 nshybrid: cells + array segments, 10 elements: 6 nshybrid: cells + array segments, 100 elements: 6 nshybrid: cells + array segments, 1,000 elements: 6 nshybrid: cells + array segments, 10,000 elements: 7 nshybrid: cells + array segments, 100,000 elements: 7 nshybrid: cells + array segments, 1,000,000 elements: 7 nshybrid: cells + array segmentsarrays, copied each way, 1 elements: 18 nsarrays, copied each way, 10 elements: 22 nsarrays, copied each way, 100 elements: 76 nsarrays, copied each way, 1,000 elements: 967 nsarrays, copied each way, 10,000 elements: 8.568 µsarrays, copied each way, 100,000 elements: 549.862 µsarrays, copied each way, 1,000,000 elements: 5.9 msarrays, copied each waycells (today, ahead of time), 1 elements: 19 nscells (today, ahead of time), 10 elements: 48 nscells (today, ahead of time), 100 elements: 559 nscells (today, ahead of time), 1,000 elements: 6.159 µscells (today, ahead of time), 10,000 elements: 66.548 µscells (today, ahead of time), 100,000 elements: 2.1 mscells (today, ahead of time), 1,000,000 elements: 61.85 mscells (today, ahead of time)Hazel's values (today's jit), 1 elements: 1.718 µsHazel's values (today's jit), 10 elements: 11.786 µsHazel's values (today's jit), 100 elements: 113.515 µsHazel's values (today's jit), 1,000 elements: 1.19 msHazel's values (today's jit), 10,000 elements: 22.6 msHazel's values (today's jit), 100,000 elements: 294.24 msHazel's values (today's jit), 1,000,000 elements: 4.37485 sHazel's values (today's jit)the interpreter, 1 elements: 27.567 µsthe interpreter, 10 elements: 53.379 µsthe interpreter, 100 elements: 379.009 µsthe interpreter, 1,000 elements: 4.51 msthe interpreter, 10,000 elements: 54.09 msthe interpreter, 100,000 elements: 675.31 msthe interpreter, 1,000,000 elements: 8.91575 sthe interpreter
Not a build of the app: Node v22.23.2 on the laptop (13th Gen Intel(R) Core(TM) i7-1370P, two cores), one run, each point the median of batches (054/drivers/crossing-bench.mjs), with hazeljs 0.0.11 (hazel-lib.js from 98c482395d). Log-log: each step on either axis is ten times the one before.
A list of Ints, into compiled code and back out: linear02 s4 s6 s8 s0250,000500,000750,0001,000,000elements in the listtime, in and back outarrays, no conversion, 1 elements: 2 nsarrays, no conversion, 10 elements: 4 nsarrays, no conversion, 100 elements: 4 nsarrays, no conversion, 1,000 elements: 4 nsarrays, no conversion, 10,000 elements: 4 nsarrays, no conversion, 100,000 elements: 4 nsarrays, no conversion, 1,000,000 elements: 4 nsarrays, no conversionhybrid: cells + array segments, 1 elements: 3 nshybrid: cells + array segments, 10 elements: 6 nshybrid: cells + array segments, 100 elements: 6 nshybrid: cells + array segments, 1,000 elements: 6 nshybrid: cells + array segments, 10,000 elements: 7 nshybrid: cells + array segments, 100,000 elements: 7 nshybrid: cells + array segments, 1,000,000 elements: 7 nshybrid: cells + array segmentsarrays, copied each way, 1 elements: 18 nsarrays, copied each way, 10 elements: 22 nsarrays, copied each way, 100 elements: 76 nsarrays, copied each way, 1,000 elements: 967 nsarrays, copied each way, 10,000 elements: 8.568 µsarrays, copied each way, 100,000 elements: 549.862 µsarrays, copied each way, 1,000,000 elements: 5.9 msarrays, copied each waycells (today, ahead of time), 1 elements: 19 nscells (today, ahead of time), 10 elements: 48 nscells (today, ahead of time), 100 elements: 559 nscells (today, ahead of time), 1,000 elements: 6.159 µscells (today, ahead of time), 10,000 elements: 66.548 µscells (today, ahead of time), 100,000 elements: 2.1 mscells (today, ahead of time), 1,000,000 elements: 61.85 mscells (today, ahead of time)Hazel's values (today's jit), 1 elements: 1.718 µsHazel's values (today's jit), 10 elements: 11.786 µsHazel's values (today's jit), 100 elements: 113.515 µsHazel's values (today's jit), 1,000 elements: 1.19 msHazel's values (today's jit), 10,000 elements: 22.6 msHazel's values (today's jit), 100,000 elements: 294.24 msHazel's values (today's jit), 1,000,000 elements: 4.37485 sHazel's values (today's jit)the interpreter, 1 elements: 27.567 µsthe interpreter, 10 elements: 53.379 µsthe interpreter, 100 elements: 379.009 µsthe interpreter, 1,000 elements: 4.51 msthe interpreter, 10,000 elements: 54.09 msthe interpreter, 100,000 elements: 675.31 msthe interpreter, 1,000,000 elements: 8.91575 sthe interpreter
The same, on linear scales: the interpreter and today’s jit grow in a straight line, and the others lie flat along the bottom next to them.

Records are the catch. Compiled code holds a labeled tuple, (x = 1, y = 2), as an array carrying its labels, and a page holds an object, {x: 1, y: 2}, so every record is converted on the way in and out, whatever shape the list has: about 0.3 s for a million, as arrays, the hybrid or cells. Only if compiled code held a record the way a page does would a list of records cross for nothing (the green line, 6 ns). A million records through Hazel’s own values ran the heap past its 2.5 GB, so those two lines stop at 100,000.

A list of records (x = Int, y = Int), into compiled code and back out: log-log1 ns10 ns100 ns1 µs10 µs100 µs1 ms10 ms100 ms1 s10 s1101001,00010,000100,0001,000,000elements in the list (log scale)time, in and back out (log)arrays, no conversion, 1 elements: 6 nsarrays, no conversion, 10 elements: 6 nsarrays, no conversion, 100 elements: 6 nsarrays, no conversion, 1,000 elements: 6 nsarrays, no conversion, 10,000 elements: 6 nsarrays, no conversion, 100,000 elements: 6 nsarrays, no conversion, 1,000,000 elements: 6 nsarrays, no conversionhybrid: cells + array segments, 1 elements: 34 nshybrid: cells + array segments, 10 elements: 358 nshybrid: cells + array segments, 100 elements: 3.042 µshybrid: cells + array segments, 1,000 elements: 38.551 µshybrid: cells + array segments, 10,000 elements: 345.578 µshybrid: cells + array segments, 100,000 elements: 23.28 mshybrid: cells + array segments, 1,000,000 elements: 270.53 mshybrid: cells + array segmentsarrays, copied each way, 1 elements: 23 nsarrays, copied each way, 10 elements: 50 nsarrays, copied each way, 100 elements: 230 nsarrays, copied each way, 1,000 elements: 2.629 µsarrays, copied each way, 10,000 elements: 8.27 µsarrays, copied each way, 100,000 elements: 648.347 µsarrays, copied each way, 1,000,000 elements: 6.6 msarrays, copied each wayarrays, each record converted, 1 elements: 51 nsarrays, each record converted, 10 elements: 425 nsarrays, each record converted, 100 elements: 3.897 µsarrays, each record converted, 1,000 elements: 24.869 µsarrays, each record converted, 10,000 elements: 483.191 µsarrays, each record converted, 100,000 elements: 28.93 msarrays, each record converted, 1,000,000 elements: 271.47 msarrays, each record convertedcells (today, ahead of time), 1 elements: 72 nscells (today, ahead of time), 10 elements: 371 nscells (today, ahead of time), 100 elements: 4.022 µscells (today, ahead of time), 1,000 elements: 29.013 µscells (today, ahead of time), 10,000 elements: 554.201 µscells (today, ahead of time), 100,000 elements: 28.25 mscells (today, ahead of time), 1,000,000 elements: 334.64 mscells (today, ahead of time)Hazel's values (today's jit), 1 elements: 19.079 µsHazel's values (today's jit), 10 elements: 58.062 µsHazel's values (today's jit), 100 elements: 515.976 µsHazel's values (today's jit), 1,000 elements: 7.8 msHazel's values (today's jit), 10,000 elements: 124.11 msHazel's values (today's jit), 100,000 elements: 1.51722 sHazel's values (today's jit)the interpreter, 1 elements: 49.933 µsthe interpreter, 10 elements: 236.793 µsthe interpreter, 100 elements: 3.6 msthe interpreter, 1,000 elements: 34.22 msthe interpreter, 10,000 elements: 362.66 msthe interpreter, 100,000 elements: 4.10159 sthe interpreter
Not a build of the app: as above, a list of records (x = Int, y = Int); the green line is a list of records the page’s shape crossing as it is, which compiled code does not do today.
A list of records (x = Int, y = Int), into compiled code and back out: linear01 s2 s3 s4 s0250,000500,000750,0001,000,000elements in the listtime, in and back outarrays, no conversion, 1 elements: 6 nsarrays, no conversion, 10 elements: 6 nsarrays, no conversion, 100 elements: 6 nsarrays, no conversion, 1,000 elements: 6 nsarrays, no conversion, 10,000 elements: 6 nsarrays, no conversion, 100,000 elements: 6 nsarrays, no conversion, 1,000,000 elements: 6 nsarrays, no conversionhybrid: cells + array segments, 1 elements: 34 nshybrid: cells + array segments, 10 elements: 358 nshybrid: cells + array segments, 100 elements: 3.042 µshybrid: cells + array segments, 1,000 elements: 38.551 µshybrid: cells + array segments, 10,000 elements: 345.578 µshybrid: cells + array segments, 100,000 elements: 23.28 mshybrid: cells + array segments, 1,000,000 elements: 270.53 mshybrid: cells + array segmentsarrays, copied each way, 1 elements: 23 nsarrays, copied each way, 10 elements: 50 nsarrays, copied each way, 100 elements: 230 nsarrays, copied each way, 1,000 elements: 2.629 µsarrays, copied each way, 10,000 elements: 8.27 µsarrays, copied each way, 100,000 elements: 648.347 µsarrays, copied each way, 1,000,000 elements: 6.6 msarrays, copied each wayarrays, each record converted, 1 elements: 51 nsarrays, each record converted, 10 elements: 425 nsarrays, each record converted, 100 elements: 3.897 µsarrays, each record converted, 1,000 elements: 24.869 µsarrays, each record converted, 10,000 elements: 483.191 µsarrays, each record converted, 100,000 elements: 28.93 msarrays, each record converted, 1,000,000 elements: 271.47 msarrays, each record convertedcells (today, ahead of time), 1 elements: 72 nscells (today, ahead of time), 10 elements: 371 nscells (today, ahead of time), 100 elements: 4.022 µscells (today, ahead of time), 1,000 elements: 29.013 µscells (today, ahead of time), 10,000 elements: 554.201 µscells (today, ahead of time), 100,000 elements: 28.25 mscells (today, ahead of time), 1,000,000 elements: 334.64 mscells (today, ahead of time)Hazel's values (today's jit), 1 elements: 19.079 µsHazel's values (today's jit), 10 elements: 58.062 µsHazel's values (today's jit), 100 elements: 515.976 µsHazel's values (today's jit), 1,000 elements: 7.8 msHazel's values (today's jit), 10,000 elements: 124.11 msHazel's values (today's jit), 100,000 elements: 1.51722 sHazel's values (today's jit)the interpreter, 1 elements: 49.933 µsthe interpreter, 10 elements: 236.793 µsthe interpreter, 100 elements: 3.6 msthe interpreter, 1,000 elements: 34.22 msthe interpreter, 10,000 elements: 362.66 msthe interpreter, 100,000 elements: 4.10159 sthe interpreter
The same, on linear scales.
Every size and way
list ofelementsarrays, no conversionhybrid: cells + array segmentsarrays, copied each wayarrays, each record convertedcells (today, ahead of time)Hazel's values (today's jit)the interpreter
Ints12 ns3 ns18 ns–19 ns1.718 µs27.567 µs
Ints104 ns6 ns22 ns–48 ns11.786 µs53.379 µs
Ints1004 ns6 ns76 ns–559 ns113.515 µs379.009 µs
Ints1,0004 ns6 ns967 ns–6.159 µs1.19 ms4.51 ms
Ints10,0004 ns7 ns8.568 µs–66.548 µs22.6 ms54.09 ms
Ints100,0004 ns7 ns549.862 µs–2.1 ms294.24 ms675.31 ms
Ints1,000,0004 ns7 ns5.9 ms–61.85 ms4.37485 s8.91575 s
records16 ns34 ns23 ns51 ns72 ns19.079 µs49.933 µs
records106 ns358 ns50 ns425 ns371 ns58.062 µs236.793 µs
records1006 ns3.042 µs230 ns3.897 µs4.022 µs515.976 µs3.6 ms
records1,0006 ns38.551 µs2.629 µs24.869 µs29.013 µs7.8 ms34.22 ms
records10,0006 ns345.578 µs8.27 µs483.191 µs554.201 µs124.11 ms362.66 ms
records100,0006 ns23.28 ms648.347 µs28.93 ms28.25 ms1.51722 s4.10159 s
records1,000,0006 ns270.53 ms6.6 ms271.47 ms334.64 ms––

Three ways to hold a list#

  1. Cells, today. null for the empty list, {h, t} for x :: xs. A pattern reads .h and .t, and :: makes one cell. Length and nth walk the list, and a page’s array is converted cell by cell on the way in and out.
  2. Arrays. A list is an immutable JavaScript array. Length and nth take constant time and a page’s array crosses as it is, but x :: xs copies xs, and so does a pattern’s tail. Hazel code mostly walks and builds lists a cell at a time, so the time grows with the square of the length.
  3. Hybrid. A list is null, a cell {h, t}, or a segment {a, i}: the elements of the array a from index i on, shared and never changed. A list literal and a page’s array are segments, made with no copy; :: makes a cell as today; a pattern on a segment reads a[i], and its tail is the segment from i + 1. Every operation has one more test than with cells.

Holes in lists#

The interpreter already allows both kinds of hole in a list, and the hybrid has room for both. An element can be indeterminate, [1, ?, 3], and the list is still a list literal. A tail can be indeterminate too, 1 :: ?: an indeterminate cons, which the interpreter’s unboxing keeps apart from literals, since a pattern [a, b] might or might not match it. Plain arrays can hold the first kind and not the second. In the hybrid, an element is any value and a cell’s tail is any value, an indeterminate one included; a pattern that meets one is an indeterminate match. That needs compiled code to carry indeterminate values at all (below).

The interpreter’s evaluated lists#

In the interpreter, arrays would change a lot for little, as far as we can see now. An evaluated list is a list literal holding an OCaml list, which js_of_ocaml makes a chain of cells, the same shape as hazel-jit’s today. Arrays there would make :: and a pattern’s tail cost a copy, unless the interpreter had a hybrid of its own, and about ninety places in the evaluator alone match on list literals and conses (transitions, unboxing, the stepper’s contexts, substitution). The interpreter’s time goes to its rewriting steps more than to its lists’ shape. Where the shape matters is the crossing between the interpreter and compiled code (mixed mode, and the library), and there every element is converted anyway. So: measure that crossing once the compiled side has its hybrid, before changing the interpreter’s lists.

Terms with holes#

Two designs, the second built on the first: fall back to the interpreter for any call that meets a hole, as mixed mode does now; then carry holes through compiled code as indeterminate values that build the interpreter’s residual terms.

  1. Fall back for the call. Mixed mode, on the hazel-jit branch now: the interpreter runs the program around its holes and calls the complete functions compiled, and a call whose argument holds a hole, or that reaches an indeterminate value, is run again by the interpreter, for that call alone. It is correct and built, but a function with a hole in it is never compiled, and a call that meets a hole pays for a compiled try and an interpreted run.
  2. Indeterminate values in compiled code. A hole compiles to a value, $R.hole(id), that carries what is needed to rebuild its term. Each elimination form checks for one: a + ? gives an indeterminate sum; a case whose scrutinee is indeterminate, where some pattern might match, gives an indeterminate match holding its rules and the values its variables are bound to; applying an indeterminate function gives an indeterminate application. When the answer comes back to the interpreter, these become its residual terms, so the result is the one the interpreter would give. The cost is a check at every elimination form, as the step budget checks at every call, and code to build each residual form. This is what running terms with holes means in full.

Together or apart? Design them together and build them apart. The list’s shape decides where an indeterminate value can sit (an element, a tail), and a cell’s tail is already free to be any value, so holes do not need arrays. Arrays (as the hybrid’s segments) pay at the edges, where a page’s list crosses with no conversion at any size, and cost a little inside, about 8% on these games; how much a program gains is how much of its time is crossing, and for a page that hands Hazel large lists that is most of it. Records must cross for nothing too, or a list of them still costs its length. So the next steps: converters by declared type (the jit’s crossing down to the cells’ line, or to nothing for arrays), records held the page’s way, then indeterminate values; and a sequence type built for splicing, ^ticket(846), beside them.

Where hazel-jit lives#

Matthew, 2026-11-23: the jit should live in as few active PRs as possible, ideally two, both meant for dev: one tracking the jit alone, and its integration into the one npm package branch. The jit-only PR is hazelgrove/hazel#2859 (branch hazel-jit, from dev, on Jane Street Core): the compiler, its value boundary and mixed mode, with the agreement tests and the evaluator tests’ sweep. The package’s PR, #2857, merges that branch (since 3f1d825455) rather than carrying a copy. The livelits line keeps its own hazel-jit (#2817, and the build of #2819), with the livelit views, on the same compiler. Moving the jit to dev found two things the livelits line hides: dev keeps both entries of a tuple with a label given twice, which compiled code cannot (so such a tuple is left to the interpreter), and dev’s statics lower a module to lets whose patterns lose their type annotations, so mixed mode finds no declared type for a module’s members and runs them on the interpreter, for now.

Records the page’s way#

Held as a page holds it, an object by its labels, a record would cross into compiled code and back for nothing, and compiled code would build one about 12 times as fast and compare two by their type 3.4 times as fast; reading a field by its label costs the same. It takes five decisions, listed below. The first two are the design: which tuples become objects, and how code that does not know a value’s type tells a record from a list’s cell or a constructor; the third, how a pattern by position reads a record, the statics mostly settle already. This is ^ticket(847), from the crossing above, where a million records cost about 0.2 s to cross however the list is held, and Matthew asked, 2026-11-24, that publishing the package wait until these questions of representation are settled. Today compiled code holds (x = 1, y = 2) as the array [1, 2] with .x and .y added to it, and a page holds {x: 1, y: 2}; the converters make one from the other on every call.

in compiled codetoday: an array carrying its labelsthe page’s objecthow
make a record of four fields49.7 ns4.0 nsan object literal, against the runtime’s tup adding each label to an array
a new record with one field changed52.5 ns5.0 nsas a literal; 13.2 ns by spread, {...r, x}
read a field by its label1.1 ns0.9 nsthe same
read a field by its position1.2 ns68.4 nsthrough Object.values; 1.0 ns with the label at that position from the type
compare two equal records25.6 ns84.7 nsby their own keys; 7.6 ns by the type’s fields, a comparison made from the type
a million records into compiled code and back173 msnothing3.8 ms with each field’s type checked, no copy
a list of 1,000 cells built4.9 µs5.5 µscells made by a class, so a plain object is a record; 6.2 µs as literals {$h, $t}, 37 µs as literals with a prototype
the same list walked4.8 µs4.4 µs5.4 µs testing instanceof at each cell; 4.4 µs as {$h, $t}

Not a build of the app: Node v22.23.2 on the laptop (13th Gen Intel(R) Core(TM) i7-1370P), JavaScript alone, written as hazel-jit’s runtime and compiled code do it today and as they would (054/drivers/records-bench.mjs); each the median of batches, and the list’s cells in five rounds, each round in a different order, the median of the rounds.

What it would change in the games#

Records are most of what crosses in some games and little in others: 97% of the nodes of a Minesweeper state (its 480 cells), 90% of Butterfly garden’s, 38% of Mahjong solitaire’s. The rest are lists, which still convert, cell by cell, until a list crosses as an array (^ticket(846), a sequence type beside List). ^report(63) timed what the crossing costs on each game’s own run: with nothing remembered, an expert Minesweeper tap took 0.31 ms through the jit, against 19 µs when the page hands back the jit’s own state. Most of that copy is the board’s records.

a state ofrecordsconstructorsarrays (lists, or tuples without labels)records, of these nodes
Downhill100100%
Minesweeper48101797%
Butterfly garden270390%
Gnome dig110473%
Checkers10150%
Bricks10150%
Snake10150%
Light trails10150%
Solitaire60522245%
Mahjong solitaire361057938%
Pinball10233%
Star wave10325%
Mahjong501723%
Go10109%

Each game’s state as a page holds it, made by its compiled rules (hazeljs-examples 66cbf53), its nodes counted by kind (054/drivers/game-shapes.mjs). A page cannot tell a list from a tuple without labels: both are arrays.

Five decisions#

All five are decided. Matthew chose A for the first (below) and took our leans on the other four (2026-11-24: “Yes, take the leans”), and each is done on the trial branch, as its last sentence says.

  1. Which tuples become objects? A tuple whose every entry is labeled becomes an object, its keys in its type’s order. A tuple with no labels stays an array. A tuple with some labels stays an array carrying them, as today, since an object puts a number key (a position) ahead of every label and would lose the order. When a tuple’s type is known, the statics already put its entries in the type’s order and add the labels it left out (LabeledTuple.rearrange, in the elaboration of a tuple against a product type). Our lean: so. Tried on 2026-11-24, at Matthew’s ask, with the two other ideas; Matthew chose A, with field reads in place: below.
  2. Telling a record from a cell or a constructor. Some of compiled code does not know a value’s type and looks at its shape: the runtime’s projection (which also takes a column from a list of rows), its equality, the label builtins, and the value boundary’s untyped way. Today a cell is {h, t} and a constructor {c, v}, and the runtime tests one key, "h" in v for a cell and "c" in v for a constructor, so a record with a field h (a height) or c (a column) would be taken for one. Options: (a) cells and constructors made by classes, told apart with instanceof: about 0.7 ns more for each cell built, and a walk costs the same; (b) their fields named $h, $t, $c and $v, still plain literals: no record has a key beginning with $, since such a label is already kept under "$" ++ label; (c) no shape test at all: equality, projection and the label builtins made from the type, as the converters are. Equality made from the type took 7.6 ns, against 25.6 ns today. Either (a) or (b) changes the games’ ahead-of-time files, whose converters, written by hand, build {h, t} and {c, v}, unless those files take generated converters (^report(63), What next). Our lean: (c) wherever the type is at hand, and (b) for the rest. Done, as leaned: compiled code’s cells are now {$h, $t} and its constructors {$c, $v}, so one key tells them from a record wherever the type is not at hand: the runtime’s projection, equality and label builtins, and the value boundary’s untyped reading and its diff. Where the type is at hand, the converters and the boundary go by it, as before. A record (h = 1, t = 2) or (c = "Lt"), which was taken for a cell or a constructor, now gives the interpreter’s answers, in tests. The games ran as fast as before (the table below is this build). What a page sees does not change; a page that keeps compiled code, as hazeljs-examples’ compiled.js files do, needs its hand-written converters changed when it is next compiled.
  3. A pattern by position against a record. Mostly settled already: when the matched type is labeled, the statics add its labels to a pattern by position (MatchedTyp.prod), so compiled code reads let (a, b) = r as r["x"] and r["y"], checked on the package’s compiled output for a declared function, a case and an undeclared literal. Only an unknown or unlabeled matched type leaves the pattern by position, and there compiled code reads r[0], which an object does not have. Checking this found a disagreement today: let f = fun r -> let (a, b) = r in a - b in f((x = 5, y = 2)) is stuck in the interpreter, which binds a to the labeled entry x = 5, while the jit answers 3 (^ticket(851)). Options for that case: (a) compiled code checks that the entry at the position has no label, and a run that meets one goes to the interpreter, as hazel-jit’s rule for anything indeterminate has it; with records as objects the check is Array.isArray; (b) a fallback through Object.values, 68.4 ns a read against 1.2 ns, which would repeat today’s disagreement. Our lean: (a), which fixes ^ticket(851) either way. Settled: (a), by ^ticket(851) for arrays and the trial’s check for records.
  4. What a page may do with an object. If compiled code keeps the page’s own object, a page that changes it afterwards changes a Hazel value, and Hazel’s values never change. The converters’ memory already assumes the page will not (“the rule for a page”, in the converters’ comment in HazelLibCore.re), and the same goes for a record the page gets back. Options: (a) state the rule, as React does for its state: what a page gives Hazel, or gets from it, it does not change; (b) freeze what crosses (Object.freeze), at least in a development build; (c) copy at the edge, which gives back most of the crossing’s cost. Our lean: (a), with (b) in development. Done, as leaned: the rule is stated in the library (what a page gives a compiled function, or gets back, it does not change afterwards), and Hazel.development(true) freezes both, all the way down, so a page that breaks the rule fails where it does; off, it costs one check a call. Its test found that a function of a tuple called with the entries spread, f(1, xs), went the old way on every call, because its declared parameter’s parentheses hid the tuple; fixed, and the test calls both ways.
  5. Checking at the edge. A page may hand over {x: 1.5} where the type says Int. Today’s converters check each field, and a call whose value does not fit goes the old way. One pass of checks and no copy cost 3.8 ms for a million records; trusting the page costs nothing. Our lean: check, as now. Kept: checking, as now.

Decision 1: A, with field reads in place#

Matthew chose A on 2026-11-24 (“A, add direct reads”): a tuple whose every entry is labeled is a plain JavaScript object, and a field read g.x compiles to the property itself. As the games play, A now takes 0.63 of today’s time (the geometric mean over 14 games), and 0.62 of it when every argument is a fresh copy. The best are Mahjong solitaire 0.27×, Pinball 0.29×, Minesweeper 0.46×. Every answer is the same as today’s. Three ideas were tried first, at Matthew’s ask (“for decision 1 -- try the first 3 best ideas (or 2 best) --- and report back”): A; B, any tuple with a label an object; and C, today’s arrays carrying their labels. B is A on every game. A alone was about even with today, for the reasons below, and the two changes here mend them.

a call, on the game’s own run, as the page playsC, todayC, reads in place (simulated)A, reads in placeA over CA over C with readsA over C, every argument a fresh copy
Mahjong solitaire64.9 µs50.9 µs17.8 µs0.27×0.35×0.75×
Pinball51.8 µs22.5 µs15.0 µs0.29×0.67×0.28×
Minesweeper23.7 µs13.7 µs10.8 µs0.46×0.79×0.19×
Butterfly garden5.8 µs6.0 µs2.8 µs0.49×0.47×0.33×
Solitaire13.3 µs8.1 µs7.1 µs0.54×0.88×1.01×
Downhill9.6 µs7.9 µs5.7 µs0.59×0.71×0.57×
Mahjong20.0 µs14.4 µs12.5 µs0.62×0.87×0.61×
Bricks4.2 µs4.2 µs2.7 µs0.63×0.64×0.63×
Gnome dig36.6 µs38.6 µs27.4 µs0.75×0.71×0.76×
Go28.7 µs22.2 µs22.4 µs0.78×1.01×0.95×
Checkers24.8 µs20.7 µs20.2 µs0.82×0.98×0.89×
Star wave11.6 µs12.9 µs10.8 µs0.93×0.84×0.87×
Snake3.0 µs3.1 µs2.8 µs0.95×0.91×0.90×
Light trails8.0 µs7.7 µs13.0 µs1.62×1.67×0.87×
all 14 (geometric mean)0.63×0.77×0.62×

Three builds, each game on its own GitHub runner, one after another (hazeljs-examples bench/847-direct, run 45532448010; 054/drivers/package-bench-847-direct.yml, with 054/drivers/package-bench-847.mjs, --runs --aot-as-is --no-interp). A: hazelgrove/hazel trial/847-records-objects at f311f4e408 (with decisions 2 and 4), CI green. C: hazeljs 0.0.12 (ec2a330996). C, reads in place: 0.0.12 with its compiled code’s field reads rewritten as A’s compiler writes them (054/drivers/direct-sim.mjs); only reads of a variable are rewritten, so it gives C a little less than the compiler would. Each game’s run is recorded once and replayed, every call given the state the last answered; a call’s time is the run’s calls summed over their number. The jit took 0.48 of the games’ own ahead-of-time files’ time with A, and 0.76 with C.

The three ideas, before the reads#

As a page plays, A alone was about even with today (1.01 of its time over 14 games), 0.86 of it when no memo helps, and a page’s list of new records crossed 6.8 to 24 times as fast; every answer the same. B, any labeled tuple an object, is A on every game: none of them makes a tuple with some entries labeled and others not.

a call, on the game’s own runC, as the page playsAA over CC, every argument a fresh copyAA over C
Mahjong solitaire64.3 µs42.6 µs0.66×403 µs333 µs0.83×
Bricks5.2 µs4.5 µs0.87×7.0 µs5.6 µs0.80×
Mahjong21.3 µs18.7 µs0.87×47.9 µs31.5 µs0.66×
Butterfly garden5.8 µs5.1 µs0.88×15.5 µs7.3 µs0.47×
Downhill8.7 µs8.0 µs0.91×9.1 µs7.9 µs0.87×
Snake3.7 µs3.6 µs0.96×2.7 µs2.7 µs1.03×
Gnome dig40.7 µs39.4 µs0.97×56.1 µs48.4 µs0.86×
Checkers21.8 µs21.8 µs1.00×17.5 µs19.9 µs1.14×
Star wave15.6 µs16.1 µs1.03×19.2 µs17.4 µs0.91×
Light trails5.7 µs6.5 µs1.13×5.5 µs5.6 µs1.01×
Go20.0 µs24.1 µs1.21×20.6 µs25.2 µs1.23×
Solitaire8.6 µs10.6 µs1.24×41.5 µs48.4 µs1.17×
Pinball32.1 µs41.1 µs1.28×29.5 µs41.3 µs1.40×
Minesweeper17.3 µs23.8 µs1.38×147 µs50.4 µs0.34×

A at 2aa0b9b451, before the reads, and C (hazeljs 0.0.12), each game on its own GitHub runner, C’s run then A’s on the same machine (hazeljs-examples bench/847-a-vs-c, run 45498058581; the driver 054/drivers/package-bench-847.mjs, --runs --aot-as-is --no-interp): each game’s run recorded once and replayed, every call given the state the last answered; a call’s time is the run’s calls summed over their number. Both against the games’ own ahead-of-time files as the reference for the answers: the jit took 0.75 of their time with A and 0.75 with C.

records in the listC, new recordsA, new recordsA as fastC, the same list againA, again
11.3 µs0.8 µs1.6×0.3 µs0.3 µs
106.5 µs1.7 µs3.9×0.3 µs0.3 µs
10039.5 µs5.9 µs6.6×0.3 µs0.2 µs
1,0000.22 ms9.4 µs23.6×0.2 µs0.2 µs
10,0002.40 ms99.8 µs24.1×0.2 µs0.2 µs
100,00045 ms1.84 ms24.3×0.2 µs0.2 µs
1,000,000458 ms67 ms6.8×0.3 µs0.2 µs

Not a build of the app: the laptop, Node v22.23.2, a page’s list of records (x = Int, y = Int) into Hazel.jit’s compiled identity and out (054/drivers/records-cross.mjs), hazeljs 0.0.12 for C and the trial’s library for A, one process each; new records made off the clock for each call, or the same list handed back. At a million, A’s 67 ms (C’s 458 ms) is mostly the list itself, still converted cell by cell until a list crosses as an array (^ticket(846)). Summing a field over the list in compiled code took the same time either way.

The interpreter does not change. Its record stays a labeled tuple of terms; only the value boundary (HazelJitValue, both ways) and the converters learn the new shapes. Merged on Matthew’s word (2026-11-24, “Yes, merge it”): the jit’s side is on hazel-jit (#2859, 9ec865976d), and the package’s on hazeljs (#2857, 20febee548), which merges hazel-jit; the package branch’s tree is the trial’s. Next: a package whose compiled output changes shape (records as objects, cells and constructors keyed with $), with its CHANGELOG saying what a page that keeps compiled code must change, and the npm publish this ticket held.

A sequence beside List#

A sequence held as a treap over views of JavaScript arrays inserts one element anywhere in 706 ns to 1.6 µs, from 1,000 elements to 1,000,000, appends one in at most 273 ns, and takes a page’s array in and out for nothing; an array copied on every edit takes 15.0 ms to insert one at a million, and cells 35.3 ms. Its costs: reading one element by position takes up to 469 ns, where an array takes tens of nanoseconds, and walking a million after twenty thousand edits takes 3.1 ms, about as long as cells (3.2 ms) and five times an array (593.0 µs). This is ^ticket(846), which Matthew asked for on 2026-11-23: “explore a new builtin sequence type, as complement to List --- Sequence or Seq, for short maybe?”, held as a balanced tree with arrays at its leaves. What matters most to him is a balance that needs no rebalancing, the levels fixing the shape so that an edit never rotates; the caching a content-determined shape allows matters less, so a level may come from any well-spread source.

How it is held. A leaf is a view of an array that is never changed: the array and a start and an end, so that splitting a leaf is two views of the same array and copies nothing. A page’s array is one leaf over it. Between two leaves is a gap with a priority, drawn here from a counter’s hash, and the tree is the one the priorities determine, the highest at the root, as in fumola’s level tree (Pugh and Teitelbaum’s), where a gap’s level comes from its symbol. An insert splits the tree at the position and joins the three parts; a join puts the higher priority on top and never rotates. A leaf of fewer than 32 elements that meets another sequence goes into the leaf at its edge when the two fit in 32: a copy of at most 32 elements, and no new gap, so the shape stays the priorities’. Every edit gives a new sequence and leaves the old one whole, as a Hazel value must, and so do the other three ways here.

held asinsert one, anywhereappend oneread one, anywherewalk them alla page’s array in and out
1,000 elements
a treap over array views (82 leaves, depth 14)706 ns163 ns85 ns1.8 µs16 ns
an array, copied2.9 µs1.4 µs26 ns656 ns4 ns
cells, today4.0 µs8.5 µs782 ns1.7 µs10.3 µs
the hybrid7.7 µs26.0 µs793 ns2.1 µs15 ns
Immutable.js’s List39.0 µs121 ns41 ns25.3 µs49.6 µs
list, funkia’s4.9 µs41 ns48 ns7.2 µs21.4 µs
10,000 elements
a treap over array views (830 leaves, depth 27)884 ns211 ns126 ns20.9 µs20 ns
an array, copied25.2 µs11.6 µs28 ns5.4 µs17 ns
cells, today45.9 µs100.2 µs13.6 µs23.4 µs75.6 µs
the hybrid64.7 µs192.5 µs22.6 µs43.2 µs23 ns
Immutable.js’s List419.8 µs126 ns40 ns212.1 µs534.4 µs
list, funkia’s3.4 µs47 ns56 ns70.8 µs258.0 µs
100,000 elements
a treap over array views (8,410 leaves, depth 30)1.3 µs227 ns262 ns385.4 µs19 ns
an array, copied1.1 ms748.3 µs29 ns65.4 µs16 ns
cells, today1.0 ms2.8 ms100.5 µs222.9 µs3.0 ms
the hybrid (one segment)1.1 ms3.0 ms29 ns65.3 µs17 ns
Immutable.js’s List5.3 ms121 ns54 ns2.9 ms8.1 ms
list, funkia’s4.1 µs87 ns83 ns685.7 µs2.9 ms
1,000,000 elements
a treap over array views (31,564 leaves, depth 37)1.6 µs273 ns469 ns3.1 ms20 ns
an array, copied15.0 ms8.9 ms45 ns593.0 µs17 ns
cells, today35.3 ms74.8 ms1.3 ms3.2 ms72.5 ms
the hybrid (one segment)34.4 ms107.1 ms55 ns684.3 µs18 ns
Immutable.js’s List52.0 ms183 ns95 ns24.2 ms77.7 ms
list, funkia’s5.6 µs82 ns161 ns6.3 ms39.4 ms

Not a build of the app: Node v22.23.2 on the laptop, JavaScript alone (054/drivers/seq-bench.mjs), each the median of batches. Before timing, every way made the same 2,000 random edits to one sequence and came out the same. The treap, and the hybrid up to 10,000, were timed after a tenth of their size in inserts at random places (at most 20,000), so the treap has many leaves; an array and cells have one shape however they are made. At a million the treap had 31,564 leaves and depth 37.

What a closure keeps#

Nothing on dev trims an environment. A function value keeps the whole environment it was made in, used or not. A function needs only its free variables, and the statics already know them for every expression, so trimming is possible. dev’s empty holes keep no environment at all, so today they are no exception to it. Compiled code already trims: a compiled function holds only what it captures, and crosses back to the interpreter holding only that.

Matthew asked, 2026-11-23: "is there any aspect of dev that trims Hazel values' environments to only contain relevant values? For empty holes, the whole env is required, perhaps -- but for other terms, esp closed terms, the env can be dropped. We experimented with this as a performance PR, IIRC, but I don't recall the exact context of that work."

An example#

Take let big = [1, 2, …, 10000] in let inc = fun x -> x + 1 in inc. The value of inc is a closure: the function, with the environment it was made in, and that environment binds big. inc never reads big, but its value holds it. Holding it costs nothing when the closure is made. An environment is a chain of bindings, shared, so a closure points at the chain and copies nothing. The cost comes later, from whatever walks a value: finishing a result, sending it from the worker to the page, or converting it for a page.

What dev does#

  1. A function keeps the whole environment. The interpreter’s rule for a function (Transition.re) wraps it as Closure(env, fun …) with the current environment, whole. A recursive function’s fixpoint keeps it whole too (FixF(p, body, Some(env))). So do the indeterminate forms that need their environment later, such as an if whose condition is a hole, or a free variable.
  2. An empty hole keeps none. The rule for an empty hole leaves its closure out; the line that would add it is commented out, marked “uncomment for hole closures”. So on dev a hole is not shown with its environment, and nothing fills a hole and resumes from it.
  3. Incremental evaluation reads only the free variables. hazelgrove/hazel#2222, “Incremental evaluation”, reuses a term’s last value when its free variables’ values have not changed, and it looks up only those: the term’s co-context, from the statics (IncrEval.restrict_to_co_ctx). That is the trimmed environment, used to decide a reuse. Values do not keep it.
  4. Finishing a result writes the environment into the body. Substitution.in_exp replaces each variable with its value, so a finished value mentions only what it uses. It gets there by copying, though: each function a function calls is copied in, at every level.

Where it was tried#

The change you remember is most likely Andrew’s. It drops environments from a result, rather than trimming them, and it is on the modular editors line, not on dev.

Trimming, as Matthew describes it#

  1. A function keeps its free variables, and a closed function keeps nothing. The statics already compute every expression’s free variables (its co-context, Info.co_ctx). The elaborator could record them on each function, and the rule for a function would keep just those bindings. A recursive function also keeps its own name, which its fixpoint binds.
  2. An indeterminate form keeps the free variables of what it has not yet evaluated. An if on a hole needs only its two branches’ free variables.
  3. A hole needs everything in scope, if hole closures come back. A filling may use any variable in scope at the hole, so a hole closure needs the hole’s whole typing context, which is the whole lexical scope. A function whose body holds a hole would then keep its whole environment. On dev today this does not arise, since holes keep no environment.
  4. What it costs, and where it pays. Each closure made gets a small environment of its own instead of a pointer to the shared one. That is a cost at every call of a function that returns a function, a curried function among them. Environments would also stop being shared, so two closures could no longer be seen to have the same environment by its identity. It pays wherever a value is walked: finishing a result, the worker’s message, the library’s crossing to a page, and a Hazel-only value the package holds whole (below).

What the jit does already#

Compiled code keeps only captures, and the crossing keeps it that way. A compiled Hazel function is a JavaScript function tagged with the Hazel names it captures and their values, in order ($R.fn(f, k, [values])). Back in the interpreter it becomes a closure whose environment holds those captures alone (HazelJitValue.of_js), with a recursive function’s own name bound again by a fixpoint. Going in, the compiler refuses a closure that carries an environment of its own (“a closure with its own environment”), so mixed mode never converts one. For the npm package, this matters to the next change on #2857: a value with no JavaScript form, such as a hole, a mark or an interpreter’s closure, crosses to a page held whole. Held, it is never walked, so a whole environment inside it costs memory, not time. Trimmed environments would make those held values small too.

Questions for the team#

Seventeen questions are open, for the team's meeting of 2026-11-17: two PRs to review, seven on mixed mode, three on what compiled code must match, three on how it lands, and two that an app met this morning. Each has our lean and what the answer decides. None blocks today's work; the answers on mixed mode decide its first step.

Answered at Matthew and Cyrus's meeting of 2026-11-13 (Matthew, 2026-11-17): "we want to mimic the step counts in the compiled code, if possible. can we make it match the interpreter in each case? if not, why not?" and "if we can mimic the step counts in the compiled code, can we support probes? if not, why not?" That settles three of the questions below, on the stepper, probes and the step budget. Our answer to theirs: yes and yes, with the care and limits in step counts and probes, as the interpreter's.

On PRs to dev#

  1. SInt at 32 bits, and overflow an error (hazelgrove/hazel#2828): agreed? Our lean: Yes, as the meeting asked. Wrapping at 32 bits everywhere would be cheaper in compiled code, but silent. It decides: Whether #2828 merges. It changes the language: a program that relied on wrapping now stops at an error.
  2. Who reviews the fix for modulo by zero (hazelgrove/hazel#2825)? Our lean: Anyone who knows the evaluator; it is small. It decides: Whether the interpreter still crashes on int_mod(7, 0).

Mixed mode#

  1. Which functions get compiled? Our lean: Let-bound functions with their whole type declared (let f : A -> B = fun ...), complete, with no probe. The elaborated type of any function would reach more, but it can hold unknowns, and the answer is converted back by that type. It decides: How much of a program runs compiled, and whether Hazel should nudge people to declare types; ^ticket(762) says that pays in the interpreter too.
  2. What does the stepper show for a compiled call? Partly answered 11-13: a compiled call counts the steps it would have taken. Our lean, still: mixed mode off while the stepper is open, since the stepper shows terms and compiled code has none. It decides: Whether stepping a program ever skips steps.
  3. Probes in compiled code: what is a probe's sample when the code that made it has no steps? Answered 11-13: compiled code counts the interpreter's steps, and with them makes the interpreter's samples (below). Until then, the plan is that a probe takes its function out of the compiled set; today mixed mode, which runs only in the tests, compiles such a function anyway, and its probes record nothing. It decides: The design of probes, the last of ^ticket(761)'s limits.
  4. Main thread or worker? Our lean: Mixed mode in the worker only, where the interpreter runs; the main thread keeps only livelit views, as now, under the step budget, which answers Cyrus's concern. It decides: Whether a long compiled call can ever freeze the page.
  5. Falling back runs a call again from the start. Is that safe for good? Our lean: Yes while evaluation has no effects. Is any effect planned (a livelit updating its model, randomness, input and output)? It decides: Whether one-call-at-a-time fallback stays correct.
  6. A program with a type error elsewhere: compile its sound functions? Our lean: Yes, per function: a value that does not fit the declared type is caught where it crosses, and that call falls back. Today a single error anywhere keeps the whole program interpreted. It decides: How often a program being edited, so often with an error somewhere, runs compiled.
  7. One step budget or two? Answered 11-13: one, in the interpreter's steps, which compiled code will count exactly. Compiled code today has its own, 50 ms or 50 million calls a run. It decides: What a budget means to a user, and what the stepper and probes count.

What compiled code must match#

  1. String length in graphemes: intended? Our lean: Keep it. Compiled code now counts as the interpreter does, with a fast path for ASCII. It decides: The meaning of string_length and string_sub for text beyond ASCII.
  2. Labeled tuples as JavaScript arrays carrying their labels: fine? Our lean: Fine inside compiled code. Labels named length, __proto__ or starting with $ are stored under $ + label. hazeljs gives a labeled tuple to JavaScript as an object, so the boundary converts. It decides: The shape of values between Hazel and JavaScript, in hazeljs and in mixed mode.
  3. The evaluator's ill-typed tests (27 stop at a failed run-time check; 4 fixpoints over _ and the like): keep them on a known list? Our lean: Keep them: they test the interpreter's casts, which compiled code never needs, since it compiles no program with type errors. It decides: Whether the consistency sweep keeps a list of known exceptions.

Landing and scope#

  1. How does hazel-jit reach dev? Our lean: In small PRs, as ^report(53) proposes: the two fixes above; then the compiler with the consistency sweep in CI and no user-facing change; then mixed mode behind a setting; then livelit views on the main thread. It decides: The order of review, and when anyone outside the prototype branch sees compiled code.
  2. Should hazeljs ship the compiler? Our lean: No: a tool at a site's build time, with only the runtime (about 17 kB) shipped to pages. hazeljs's library is already 2.8 MB. It decides: How an app like the oracles gets compiled code without CI's help.
  3. Undeclared result types cost a step 5 to 7 times (^ticket(762)): fix in elaboration? Our lean: Yes: put the result's ascription once around the body, where the typed form has it. It changes where the interpreter inserts its run-time checks, so it needs an owner who knows elaboration. It decides: Whether every Hazel program, not only compiled ones, gets the speed.

Met by an app#

The astrology oracle (hazeljs-oracles 0.0.15, ^ticket(768)) is eleven modules of numeric code, the Sun, Moon and planets from Meeus's and Schlyter's series, run by hazeljs. Writing it met two problems in the interpreter's side of Hazel, filed this morning.

  1. An answer that is a function grows past gigabytes (hazelgrove/hazel#2832): fix Evaluator.finish? Our lean: Yes. finish substitutes the environment into the answer, so a function that reaches earlier modules copies their closures into it, nested; leave a closure in the answer as a closure, and substitute only for display. Compiled code never meets it: a compiled function is a JavaScript function. It decides: Whether a hazeljs page can take functions from a program of many modules. The astrology page cannot today, so it builds the whole program again for each chart, about 1.3 s.
  2. Float literals print with six decimals (hazelgrove/hazel#2831): print them so they read back? Our lean: Yes, the shortest form that reads back as the same number. Today a literal with more decimals sends its module to the recovering parser, whose cost grows much faster than the module. Compiled code already prints floats exactly, and evaluation compares them by value, so the interpreter and compiled code agree on them; only parsing and the terms' own equality (six decimals) are affected. It decides: Whether numeric programs can write constants as they are; the astrology rules write long ones as ratios.

What next#

hazel-jit has its own PR for dev now, merged into the package’s branch; the hybrid lists, measured on the games, do not pay; next, converters by declared type, then holes as indeterminate values (above). In order:

  1. The jit-only PR, hazelgrove/hazel#2859 (hazel-jit), green in CI, and #2857 taking the jit from it rather than from its own copy.
  2. Done 11-23: the hybrid lists, prototyped on hazel-jit-lists and measured on the seventeen games: about 8% slower ahead of time and 4% through the jit (above). Cells stay.
  3. Converters by declared type: a page’s values written straight into compiled code’s shapes and back, without Hazel’s own values between, for the jit’s calls and mixed mode’s; ^report(63) found this crossing to be most of the jit’s time on 34 of 45 operations.
  4. Mixed mode’s types from the statics: each function’s type from the info map, not from its annotation, so a module’s members compile on dev and a function needs no annotation.
  5. Records held the page’s way in compiled code (an object by its labels, not an array carrying them), so that a list of records, as arrays, crosses for nothing too: measured in JavaScript and laid out as five decisions (^ticket(847)); then the trial branch, once they are answered.
  6. Indeterminate values in compiled code (above): a design for each elimination form’s residual, then a prototype on the hybrid lists, checked against the interpreter by the evaluator tests’ sweep, whose programs with holes it would then compile.
  7. The crossing between the interpreter and compiled code measured, before any change to the interpreter’s own lists (above).
  8. Done 11-18, build 50: the slides' builtins (trial/761-slide-builtins): an operator passed as a function, and to_lvs, so more of the slides' programs compile: 20 of the 129, against 15. Its full tests had gone past their 100 minutes twice (build 49's took 72; CI runs 44146528138 and 44165874889). With the consistency check's timing runs left to the quick tests, they finish in 77 minutes (CI run 44184122601). A trail CI now prints shows the slides' check taking 13 of them, 11 of those on twenty slides, 91 to 110 in the check's order, the livelit playground's among them, each run once each way. Build 49's timing rule ran each slide at least ten times, which likely explains why its quick tests ran long whenever a test was added, as the astrology test was (not yet checked). The run found a real difference: two b2t2 examples, t.get_acne with t a list of rows, which the interpreter projects through the list, each row's field, and hazel-jit compiled as a JavaScript property read, undefined on a list. Projection now goes through the list as the interpreter's does, with two tests, and all 20 compiled slides agree (CI run 44197056910). One evaluator test then parted, (true).a, which the interpreter leaves stuck: the compiled run now stops as indeterminate there, where it once read undefined and carried on, and the check counts that as agreeing. All of CI then passed (CI run 44211080673; the full tests in 92 minutes, against 77 before, so they are close to their limit), and the branch became build 50.
  9. The astrology oracle compiled whole (trial/768-astrology-timed, ^ticket(768)): measured, 170 times as fast as the interpreter for one reading, the same answer. Its quick tests' overrun was build 49's timing rule: merged with build 50, they pass (CI run 44320263066). And the page casts compiled by default since hazeljs-oracles 0.0.16 (above). Left: mixed mode's measure of it, in the full tests now running.
  10. Mixed mode across modules: a module's member that calls another module's (Lines.becomes in the I Ching's reading) compiled too, so the I Ching's rules compile whole.
  11. Mixed mode's crossing cost: a call from interpreted code to a one-line compiled function costs more than the function (500 calls of sq, 27 ms mixed against 22 interpreted). Convert a large value once and remember it, and leave very small functions to the interpreter.
  12. Step counts in compiled code (^ticket(767)): a counter from the measured costs, each evaluator program's count compared with the interpreter's in the sweep.
  13. Probes in compiled code, on the step counts, after the team's answer.
  14. Reviews for hazelgrove/hazel#2828 (SInt) and hazelgrove/hazel#2825 (modulo by zero).
  15. A cheaper step counter (^ticket(763)); the probe drawer's stepper checked in the browser (^ticket(760)); the run-time type checks of an undeclared result type counted (^ticket(762)); a build-time compiler for hazeljs apps (^ticket(765)).

Next steps for Matthew and others#

The steps above are the agent's. These need a person: answers and a landing plan from Matthew and Cyrus, two reviews from anyone who knows the evaluator, an owner for one change to elaboration, and a first project for John.

How this was put together#

The plan is Matthew Hammer's summary of the meeting, quoted as he wrote it, and the dashboard's tickets 756 to 764. The sweep's numbers are the report it prints in CI's log: build 47's fast checks (CI run 43887985051), and the first sweep's full tests (CI run 43754503317). The Witch's numbers come from the Firefox check on GitHub's machines (scripts/jit_slides.py, run by the jit.yml workflow of hazelgrove/hazel), one run per build, with the runs named in the builds table. The view a frame and the compiled run a frame are its page timeline over a 3 s drag of the neck slider. The compiled run at a step is its time before the first redraw at each of four slider steps. The Node figures are microbenchmarks on JavaScript written as hazel-jit writes it, not builds of the app. SInt's behaviour was checked through hazeljs 0.0.6. Everything the page shows is in data/numbers.json.

The data#