Hazel reports · ^report(53) · the team's review · 2026-11-10, revised 2026-11-10 12:47 MST · work in progress · for the Hazel team

Fewer, Deeper Fixes

^report(48) gathered every cost the series had measured in how Hazel runs a program and draws it, 196 of them, and called the whole "A Thousand Cuts". On 2026-11-09 Matthew Keenan answered it on Slack: fix them together, in a few well-chosen changes, not one at a time. Here are his message in full, Matthew Hammer's replies, and a response to each of his points from what the series measured. Matthew Hammer, 2026-11-10: "Let's write a report with this feedback, and our reasoned response to it."

Outline#

  1. In short: we agree with his overall point. Six fixes, most of them his, would address the causes of 116 of the 196 costs. The agent's code is a prototype and a measurement, to be redone by hand.
  2. Matthew Keenan's message, in full.
  3. Matthew Hammer's replies, on 11-09 and 11-10.
  4. Point by point: what the series measured on each, and our read.
  5. Six fixes, and the costs whose causes each addresses.
  6. What the prototype is for: the hazel-jit branch as a measurement, and ^ticket(721) as the special case he warns about.
  7. What the message left out: the root causes no fix here addresses, each with a question for a gut opinion.
  8. What next, the builds, and how this was put together.

In short#

We agree: a few well-chosen fixes, each written by hand and reviewed, are worth more than many separate ones, and our own record on the hazel-jit branch shows the risk he names. ^report(48)'s ledger files each of its 196 costs under one of 19 root causes. Six fixes would address the causes of 116 of them: Merkle hashes in the grammar, ids made cheap and kept temporary inside the evaluator, a value's type checked once, the worker as a language server, per-item statics landed on dev, and derived state and rendering through Bonsai. All six come from his message.

Wherever the series has numbers on one of his points, they bear out his gut reaction, with two refinements: a hash belongs on the node it describes, not in a side table, and a probe's environments are large only where they cross to the page, not in memory. The code the agent wrote stays a prototype. It answered fast whether a livelit's slider can show its step in tens of milliseconds, and which of the changes mattered; ^report(52) ranks them and orders a redo by hand in small increments.

Matthew Keenan's message#

His overall point: an agent fixing the costs it found one at a time would spread special-case logic through the codebase; a few well-chosen, well-implemented fixes and simplifications would do more in the long run. He sent it on Slack on 2026-11-09, in reply to ^report(48), as gut reactions rather than invariants, and asked to hear about any important facets he skipped (below). It is quoted as he wrote it.

my thoughts on your cuts that you can feed into your agent in case you want to inject more prompting/data/opinions into it. lmk (or get your agent to lmk) if there’s any important facets I skipped over that need a gut opinion.

note these are all gut reactions, I haven’t spent too long thinking about any particular one, please don’t treat any of them as invariants

Overall: I’m really really really scared of having an agent fix a thousand cuts it’s found. Especially I’m scared that it’ll fix them all separately. A lot of these can be fixed together. I’d say agent-generated prs, at least in 2026 still generally decrease the quality of the codebase rather than increasing it; a thousand independent fixes could go a long way to making the codebase harder to use; and I would think we could get more out in the long term if we do a few well-chosen well-implemented fixes and simplifications instead of a thousand things that only fix certain cases and plaster on special-case logic throughout the codebase

Ids-on-every-term:

Matthew Hammer's replies#

Matthew Hammer agreed that the agent's code lacks quality, and named what it is for: cheap prototypes, and quick answers to questions that would otherwise take days or weeks. He also apologized for the agent's wording. "Death by a thousand cuts" was his phrase for how expensive Hazel's operation is overall; the agent took to calling each cost a "cut", and then each improvement too. From this report on, a cost is a cost and an improvement is a change, and the earlier reports are being revised to match.

On Slack, 2026-11-09, to the team and to Matthew Keenan:

Thanks for the detailed feedback!

Point taken about the relatively low quality of machine-generated, machine-architected code. The way the machine talks about the code is also sub-par, in my opinion. It started calling everything a “cut” when I originally meant “death by a thousand cuts”to refer to the relatively expensive way that Hazel operates. It started calling each improvement a “cut”, which definitely isn’t “my voice” for writing anything to the agent. I apologize for that.

I’m not sure which PR you’re thinking about most, or maybe just in general, but I generally agree.

I think of the main benefit of the agent-based code generation to be cheap prototyping, to check the viability or actual experience of an idea, and quick scientific inquiry into questions that would take days or weeks to answer otherwise.

To be sure, I agree that the code it generates still lacks quality, generally. I never meant to suggest otherwise.

And on 2026-11-10, with a link to ^report(52), where it stands:

In the expectation that we want to polish or even totally redo some agentic codegen in my PRs, I’m asking the agent to review the prototype JIT system and other performance stuff for livelits, and rank the components/changes in order of what helped most.

The code quality may be low, but I can now get a redrawn picture in 31ms instead of several seconds later. Seems like there’s a lot of value here, regardless of the code structure.

Point by point#

Each of his points that the series measured is borne out by the numbers; the table gives them, with our read and the fix that takes the point up. Each row cites the report that measured it. Nothing here is a new run: the numbers are the ones those reports give, for the builds they name.

His pointWhat the series measuredOur readFix
Overall: a few well-chosen fixes, not a thousand separate onesOur own last five days on hazel-jit (^report(52)): 120 commits on one branch, 9,200 lines added to src/, 6 of its 10 ingredients with no test of their own, 7 commits that only fixed the one before (and 3 more since), and caches keyed on object identity, two of which made a drag slower before they were fixed (builds 31 and 33).Agreed, and our record shows the risk he names. The 196 costs in ^report(48)'s ledger come down to 19 root causes; six fixes would address the causes of 116 of them (the figure below).all six
Ids: changes internal to Id.mk or id equality; the old id libraryId.t is Uuidm.t (uuidm 0.9.8). On dev, Id.mk makes each id through Uuidm.v4's byte copy, about 20% of all time in a profile of a JS call into Hazel (^report(25)); on the hazel-jit line it builds the same 16 bytes from a counter by one string concatenation (^report(45): 906 ids in 0.044 ms, from 0.29). The interpreter minted 461,422 ids for a 33,847-node picture (^report(9)).Agreed: the trial line's Id.mk is the internal change he describes, and can go to dev as it is. Replacing uuidm is possible behind Id's interface too, keeping the serialized form.2 · Ids: cheap to make, and temporary inside the evaluator
Evaluation's ids: don't let temp ids escapeVariable lookups make 38% of the ids the evaluator mints, environment frames 20%, ascriptions about 30% (^report(9)); fresh ids make the worker's requests 1.99 times larger and its results 11% (^report(9)). A local experiment with content-derived names removed 92 to 97% of them, at 11 to 31% more time.Agreed, and simpler than our content-derived names: Id.temp inside the evaluator, real ids only for what leaves it, so the editor (tylr) still sees unique ids.2 · Ids: cheap to make, and temporary inside the evaluator
Ascriptions' run-time checks: more checks than they should?Ascribing a constructor application compared two copies of the Html type at every node of a view: 88% of a 15 to 17 s Polygons click (^report(17)). The same ascription re-checks inside the woods picture's view (14 to 16%, ^report(25)).Agreed that the count is the problem: #2661 (Merkle-hashed types) and #2681 (a memo) make each check cheap but leave them repeating. Counting checks per value comes first.3 · Check a value's type once
Quadratic list walking: the same one back again?This one comes from an annotation: a recursive function whose list parameter is annotated checks the whole rest of the list at every call, n calls over n cells: 205 ms at 400 elements (^report(17)), the World rule 144 ms at 16x16 against 18 ms unannotated (^report(25)).We cannot tell whether it is the case he fixed before; this one is quadratic because each recursive call re-checks its argument against its annotation, not because of how the list is walked.3 · Check a value's type once
Something resembling the cast calculusTen of the 196 costs are run-time type checks (ascriptions, casts), the quadratic one among them.Agreed as a direction, and a research question, as he says; it is the fix that removes the checks rather than caching them.3 · Check a value's type once
Variable lookups needn't mint ids38% of the evaluator's ids (^report(9)).Agreed: Id.temp there is the cheapest principled change on the list.2 · Ids: cheap to make, and temporary inside the evaluator
The evaluator re-traversing what is finalThree costs: the evaluator visits values that are already final (a third of a loop's passes take no step, ^report(29)); a value held in a closure is re-stepped when substituted into each call (^report(25)); a function Hazel's JS library returns has its environment substituted into its body, so a held list is re-evaluated at every call (^report(29); fixed on trials, #2808 open).Consistent with his diagnosis: the cases we found come through substitution, on the library path, rather than through environment lookups. Checking that the final flag is set on those paths is the next step, before any fast path.—
The worker-editor transition: send it fast, or a language server25 of the costs are the worker trip or the serialization across it. The answer went 5.4 MB, 0.42 MB, 198 KB (reports 046, 051); the request went whole whenever the page's statics did not match the per-item analysis (build 44, ^report(52)).Agreed that shrinking is the cart before the horse. hazel-jit has taken the worker off the path to the picture for livelits, which makes the language-server design easier to try: the page asks for what it shows.4 · The worker as a language server
Environments in probes: fundamental, or a sharing leak?A probe's environment was written out whole: the Drawing module in the sample of a probe whose value is a few bytes, 4.14 MB of a 5.4 MB answer (^report(46)).Not fundamental: in memory the environments share, but each sample's environment was serialized on its own across the worker boundary, and the worker's sharing pass found almost nothing to share (1.4 to 1.6 s a result, dropped in build 3 of ^report(50)). The leak is at the boundary.4 · The worker as a language server
Andrew's branch incrementalizing statics and MakeTermThat is #2469 (modular editors): per-item statics (DefStatics) and incremental MakeTerm. It works: #2597, without it, re-ran statics on the whole program at every livelit commit, 3.5 s of a 5.8 s profiled release; a release took 3.76 s there against about 0.35 s on #2635, which has it (^report(1)).It is the base of everything in ^report(49) to ^report(52), and not yet on dev.5 · Incremental statics, landed as it is
Lets always recursiveEvery let-bound function takes statics' recursive path, and the passes multiply with nesting, up to 4 to the depth: nested lets took 400 s (^report(1); #2603, open, takes it to 0.6 s).Worth trying: always-recursive lets remove the multiplier at its source rather than special-casing it. A language decision for the team; we can measure it.5 · Incremental statics, landed as it is
Incremental statics: don't let perfect be the enemy of the goodRe-analysis per edit is the largest family, 28 of the 196 costs.Agreed: land per-item statics first. ^ticket(721)'s literal patch (build 45) is not that, and should wait for it.5 · Incremental statics, landed as it is
Merkle hashing in the grammar, or a ppxReuse checks with a Merkle hash: 283 to 26 ms on #2635, 2,743 to 410 ms on dev (#2673, open). Types: 15 to 17 s to 2.0 to 2.2 s (#2661, open). But ValueHash keeps its hashes in a WeakMap side table that slowed as it grew (2.3, 5.5, 6.3 s; 98 MB of what four edits kept, reports 009, 014).Strongly agreed, with one lesson from the measurements: the hash belongs on the node, not in a side table.1 · Merkle hashes in the grammar
Incremental evaluation inside functionsIncremental evaluation saves nothing on a slider edit (Witch 754 against 701 ms from scratch, ^report(9)); every slider edit re-evaluates 85 to 95% of the figure (^report(11)).Agreed that this is the root of 'it doesn't work on sliders'. hazel-jit sidesteps it for livelits by compiling the run (a step in 2 to 3 ms), but the worker still re-evaluates; caching by call-stack ids or names is the real fix.—
Undo keeping whole editor state; BonsaiAbout 92 MB kept per edit, uncapped (^report(14)). Andrew Blinn's compaction held #2597 to 159 MB (^report(20)), but restoring a compacted entry rebuilds what is derived: a redo took 6.0 to 6.5 s there, against 2.7 to 3.1 s before (^report(14)).Agreed: undo should keep only what is not derived.6 · Derived state and rendering through Bonsai
Rendering through BonsaiThe page's view and redraw are the second-largest family, 25 of the 196 costs.Agreed; our own caches this week are hand-written incrementality.6 · Derived state and rendering through Bonsai

The two refinements, where the measurements add something to his reaction. A hash belongs on the node: ValueHash keeps its hashes in a WeakMap beside the values, and three identical evaluations took 2.3, 5.5 and 6.3 s as the table grew, while an experiment that kept the hashes on the values held at 2.2, 2.5 and 2.2 s (^report(9)). And a probe's environments share in memory; what made them large was each sample's environment written out on its own for the trip to the page, where the worker's sharing pass found almost nothing to share (^report(46)).

Six fixes#

Six fixes would address the causes of 116 of the 196 costs; the largest families they leave are the interpreter itself and the JS boundary. The figure files each cost under its root cause, as ^report(48)'s ledger does, and colors it by the fix that addresses that cause. "Addresses" is a judgment, not a measurement: a fix aimed at a cause need not remove every cost filed under it, and some costs are already fixed on one branch or another.

The 196 costs in report 048's ledger, by root causecolored by the fix proposed here that addresses the cause; grey: no single fixre-analysis per edit (statics, parsing)28 · fix 5the page's view and redraw25 · fix 6serialization (Marshal, sharing)15 · fix 4the JS boundary (js_of_ocaml)15incremental reuse checks12 · fix 1interpretation itself12ids on every term11 · fix 2the worker trip10 · fix 4run-time type checks (ascriptions, casts)10 · fix 3other8environments and substitution8persistent maps and allocation (GC)7values are terms (open terms, holes, closures)7probes and samples6parsing on load5undo and history5 · fix 6trampolines and stack safety4scheduling (worker slices, message cadence)4data representation (flat lists, no maps)4
Not a build of the app: ^report(48)'s ledger of the costs the series measured from ^report(1) to 047, each filed under one root cause. The six fixes proposed here address the causes of 116 of the 196 costs; the rest (the interpreter itself, the JS boundary, environments and substitution, values held as terms, and others) have no single fix on this list.
FixWhat it isCosts whose cause it addressesFirst stepFrom our own work
1. Merkle hashes in the grammarA hash on every term, type and value, kept on the node itself (in Grammar, or by a ppx), so that equality is a hash compare and a cache key is cheap. It retires the family of compares that walk two equal copies node by node.12 (incremental reuse checks)Hashes on the node, not in a side table: the experiment of ^report(9) put them on values and the slowdown with the heap went away (2.3, 5.5, 6.3 s to 2.2, 2.5, 2.2 s).Our week on hazel-jit met the same family again and again: build 31's check, keyed on a livelit's definition, found a new copy at each lookup (a drag 15.1 ms a frame, from 8.2); build 33's shape cache compared a model's value at every frame (16.1 ms); and the view cache compares 104 sample values by value at each answer, 2 to 8 ms (^report(51)). Each got its own cache; a hash on each value would serve them all.
2. Ids: cheap to make, and temporary inside the evaluatorId.mk made cheap inside Id, its interface unchanged; and every id the evaluator makes an Id.temp, real ids given only to what leaves the evaluator, as Matthew Keenan proposes.11 (ids on every term)Port the trial line's Id.mk (one string concatenation an id, ^report(45)) to dev; then audit the evaluator's mints (variable lookups 38%, environment frames 20%, ascriptions about 30%, ^report(9)).hazel-jit's compiled run works on JavaScript values and makes ids only for what it gives back to Hazel as terms; making those took almost half of the way back until Id.mk was made cheap (^report(45)).
3. Check a value's type onceAn ascription or annotation checks a value once, and a value known to have a type is not checked against it again: something resembling the cast calculus, or a mark on checked values. It retires the repeated checks, including the quadratic walk of an annotated recursive helper over the rest of its list.10 (run-time type checks (ascriptions, casts))Count the checks before caching them: for the World rule, how many times each list cell is checked against [Square] per move.Two of the open fixes cache the checks (#2661 hashes the types, #2681 memoizes them); as Matthew Keenan says, a cache can hide that the checks repeat.
4. The worker as a language serverThe worker keeps the program, its statics and its run, and the page asks it for what it shows (a probe's samples, a livelit's answer) rather than receiving a whole answer after every run.25 (the worker trip, serialization (Marshal, sharing))Write down which of the page's readers need the worker's answer at all, now that hazel-jit draws livelits from the page's own compiled run.Our changes to the answer (5.4 MB to 198 KB, ^report(46) and ^report(51)) were the cart before the horse, in his words; with hazel-jit the picture no longer waits for the worker, and what is left of the trip is the page taking the answer in, 50 to 60 ms (^report(52)).
5. Incremental statics, landed as it isPer-item statics (Andrew Blinn's DefStatics, on #2469) to dev first, as the good-enough first pass; finer grain later, by measurement.28 (re-analysis per edit (statics, parsing))Land #2469's per-item statics on dev.^ticket(721)'s patch for a livelit's literal (build 45) is the special case Matthew Keenan warns about: one kind of edit, patched by hand inside DefStatics. It measures what finer-grained statics would buy (12 to 28 ms a slider step on the Witch), but it should not land ahead of the general version.
6. Derived state and rendering through BonsaiSeparate what is derived (syntax, statics, layout, views) from what is not, so undo keeps only the latter and rendering recomputes only what changed.30 (the page's view and redraw, undo and history)Find Matthew Keenan's bonsaification branch and measure it on one slide.Most of our week's caches (projector data, the view cache, the outline's memos) are hand-written incrementality of the kind Bonsai's model provides; each is one more place a key can go stale.

Two of the six can start at once and touch little else: Id.mk's cheaper ids are already written (one module, its interface unchanged), and per-item statics are written and running on #2635. Merkle hashes in the grammar and checking a type once are design work first; the language server and Bonsai are the largest, and would change how the page and the worker divide the work.

What the prototype is for#

The hazel-jit branch answered, in five days, whether a livelit's slider can show its step in the picture in tens of milliseconds. It can: 20 to 30 ms on the Witch slide, from 4.2 to 6.5 s. Its code measures what each change is worth; it is not code to land. That is the use Matthew Hammer names for agent-written code. ^report(52) ranks the ten changes that mattered by how much each helped and orders a redo by hand in nine increments, each its own pull request with its own tests. Our own record there is the risk Matthew Keenan describes: 120 commits on one branch, 6 of its 10 ingredients without a test of their own, 10 commits that only fixed the one before, and caches keyed on object identity, two of which made a drag slower before they were fixed.

^ticket(721), finished this morning as build 45, shows both sides. When a slider's step changes only the literals in a livelit's model, the item it edited is patched rather than analyzed again: a step's statics went from 19 to 53 ms on build 43 to 12 to 18 ms on build 45, and the edited item's part from 13 to 42 ms to 3 to 6 (one run each, on the Witch slide, below). That answers a question: finer-grained incremental statics would buy 10 to 35 ms on a slider step. It is also special-case logic: one kind of edit, patched by hand inside DefStatics, and a first attempt (build 44) sent the worker the whole program instead of the edited item. We propose keeping it as that measurement, and not landing it ahead of per-item statics on dev (fix 5).

What the message left out#

The root causes no fix here addresses: the interpreter itself and the JS boundary are the largest, 12 and 15 costs. Matthew Keenan asked to hear about facets he skipped that need a gut opinion; these are the ones the ledger has, each with what the series measured and the question we would put to him.

Root causeCostsWhat the series measuredThe question
interpretation itself12The interpreter is slow at what any interpreter is slow at: a livelit's render 40 times slower than compiled with the trip in and out, a recursive sum of 1,000 1,152 times (^report(45)).Should a compiler like hazel-jit become a second way to run Hazel programs, beside the interpreter, and if so who keeps the two in step? Or should it stay a livelit's fast path?
the JS boundary (js_of_ocaml)15js_of_ocaml's generic calls (11.6% of self time), values converted from JS as syntax the evaluator steps back into a value (56% of a call's floor), Uuidm's byte copy (^report(25)).Is there a representation of values that crosses the boundary cheaply, so that a JS call into Hazel does not rebuild what it was given?
environments and substitution8A value held in a closure is substituted into each call and stepped again (^report(25)); environment lookups 7.2% of a loop (^report(35)).Substitution or environments for the evaluator's own steps: is the final flag he mentions enough, or is it time to evaluate with environments throughout?
values are terms (open terms, holes, closures)7The Witch's picture sent as terms: 142.2 KB and 24.0 ms to encode and decode, against 48.0 KB and 6.09 ms as plain data (^report(47)).Should closed, first-order values (numbers, strings, lists, records of them) have a representation of their own, apart from terms?
persistent maps and allocation (GC)7Garbage collection 18% of a JS call's floor, 19.8% of a plain walk's self time (^report(25)); a pause of 20 to 35 ms once a slider step (^report(52)).Which of the evaluator's maps and copies could be mutable and local, or shared?
data representation (flat lists, no maps)4Hazel has no map, so a rule walks a list to find a square: 254 ms at 64x64, against 0.54 ms for Fumola's HashMap (^report(27)).A map in Hazel's library, or in the language?
parsing on load5Opening a program parses it whole (^report(48)'s five costs).Worth incremental parsing, or only a cache of parsed programs?
trampolines and stack safety4The evaluator's trampolines are part of a loop's per-pass cost (^report(29)).Is stack depth still the constraint that made them necessary?
scheduling (worker slices, message cadence)4How often the worker yields and sends (^report(4): 5.8 to 6.2 s of a 10 s change idle between slices, fixed).Folded into the language-server design (fix 4)?

What next#

  1. Agree as a team on the six fixes, or a different short list, and their order. Ids and per-item statics can start now.
  2. For ascriptions, count the checks per value on the World rule before caching anything, as he suggests.
  3. Find Matthew Keenan's bonsaification branch, and Andrew Blinn's notes on #2469, and measure each on one slide.
  4. Keep the hazel-jit branch as the measurement it is; redo its changes by hand in ^report(52)'s order, each only where it still helps once the deeper fixes land.

The builds#

This report names three builds, numbered as in ^report(50) to ^report(52): each is the one before it plus one change, on trial/694-view-jit (hazelgrove/hazel#2817); builds 44 and 45 were checked on a side branch, trial/694-view-jit-35, and are on trial/694-view-jit since 11-10. Their numbers are from one run each of the Firefox check on the Witch slide, steps 1 to 4 of its slider.

BuildCommitRunWhat it addsStatics, a stepThe edited itemThe worker's request
43421e30a04b42830234099a projector's update walks only what holds it19 to 53 ms13 to 42 msthe edited item, 10 KB
44d90a8cf13542838899176a model-only commit patched after DefStaticsnot timednot analyzedthe whole program on step 1, 894 KB
459ae518ffe742850343281the patch inside DefStatics: the edited item patched, not analyzed12 to 18 ms3 to 6 msthe edited item, 9 to 10 KB

Build 45's own test (test/Test_ModelPatch.re) did not compile on its first CI run; the fix is fc1103900d. CI passed on it (run 42855280858; GitHub's runner lost contact during the first try of the full tests, and the re-run passed), and trial/694-view-jit moved up to it on 11-10 at 12:46 MST. Build 45 is on the prototype branch, not on dev.

How this was put together#

Matthew Keenan's message and Matthew Hammer's replies are quoted from Slack as Matthew Hammer pasted them. The costs, their root causes and the numbers in the point-by-point table are ^report(48)'s ledger (048/data/ledger.json), each checked against the entry it cites; the figure counts that ledger's root causes. The six fixes, which cause each addresses, and the questions in the last table are our judgment. Build 45's numbers are from the marks of its run (statics, statics: items, worker: request decoded) kept in ^report(51)'s data/runs/. Everything the page shows is in data/numbers.json.

The data#