Hazel reports · ^report(47) · design note · 2026-11-08, updated 2026-11-09 21:39 MST · work in progress · for ^ticket(718)
First-Order Data in a Form of Its Own
A design note for dev. Closed, first-order values (numbers, strings, booleans, lists, tuples, constructors) pay for the generality of open terms wherever they go: ids on every node, environments substituted into them, a hash of every node to share them. Matthew, 2026-11-08: "let's try to do something systematic for dev that solves this, at the cost of another representation form for first-order data, and no closures", and then: "I'm imagining a special case of Value (or whatever it is called in the core language) def that's especially efficient to serialize for first-order data." And: "Fumola is more efficient than Hazel for these values, and we should try to experiment with these other, more efficient design ideas and submit a plan to the group based on what we find." This note proposes that value form, how it is made and sent, and the experiments to run first; the plan for the group comes from what they find.
Outline#
- The goal: a 60 fps floor for small edits; on the Witch slide a step now shows in 19 to 24 ms, its run compiled, and the probes wait 1.4 to 2.0 s for the worker.
- Why: the same cost, found again and again; last on the Witch slide, where one module written out in a probe's environment was 3.8 MB of a 5.4 MB answer.
- The form: a
Dataterm, a value made only by the evaluator, with no ids, holes, closures or environments inside it. - Beside Fumola's Value: Fumola keeps values apart from terms, and its first-order cases serialize as they are; the cases here are those, inside Hazel's terms.
- Why it is cheap to send: no ids, no sharing to find, numbers packed; or not encoded at all, as plain JS values over the browser's own copy.
- Which code made a value: kept beside it, keyed by the code's id, as probe samples already are, and as Fumola's graph keeps it; never in the value.
- When a value becomes data: first where values leave the evaluator, then in the evaluator itself.
- Where it pays, in order: probe samples, the worker's messages, livelit models, hazel-jit, the evaluator.
- What it costs: a second form wherever values are read, and the same answers both ways.
- What it is not: no sharing, no closures, no holes, no types inside.
- The experiments: the same values as Hazel's terms, as data, and as Fumola's values, sent, built and read; measured before anything is proposed.
- Experiment 1: sending the Witch's picture: as data, 3.0 times smaller and 2.5 to 4.3 times quicker to send than as terms; as JS values or JSON, quicker still once made; Fumola's side beside it; and treemaps of where the bytes are.
- Experiments 3, 4 and 5: a run mints about 189,922 ids, 0.2 to 0.3% of the evaluator's time to mint; printing the picture is 50 to 54 times quicker as data; into JS, about the same either way; Fumola's door into JS is slower than either.
- Experiment 2, a first slice: built node by node, the picture costs about the same as data as it does as terms without ids; an id with its tag, kept in a tree, costs 59 to 91 ns, so a run's ids are 1.0 to 2.5% of the evaluator. Building values as data would save at most a couple of percent: the evaluator's time is its own work, so the run has to be compiled.
- The plan for the group: written from the experiments and from two slices tried on the livelits branch, which took the Witch's worker answer from 590 to 198 KB; a draft of its slices, and questions for Matthew.
The goal: 60 fps for a small edit#
A slider's step drawn in 16.7 ms, a 60 fps floor for small edits, as a JS app holds. On the Witch slide a step now shows in 19 to 24 ms and a drag runs at about 58 frames a second, the slide's run compiled in the page (^report(51)); the probes still wait for the worker's run, whose answer comes 1.4 to 2.0 s after the step. Matthew, 2026-11-08: "I'd really like Hazel to have a floor of 60FPS for small edits (sliders changing), just like in JS (but well beyond there, obviously)." And: "And each obstacle is worth studying, and overcoming." When this note was begun, a small edit on the Witch took 1.3 to 1.7 s, about 80 to 100 times the goal (^report(46), two cuts, and sharing dropped): the worker's evaluator 0.81 to 0.92 s; the page's own work, about 0.4 to 0.8 s, most of it the whole slide's view drawn again, about 117 ms each time and five times an edit; the trip between the worker and the page, 79 to 102 ms. First-order data is one obstacle among these: it is in what the evaluator builds and in what the worker sends, and the trip it shortens is now the probes'.
Why#
Hazel holds every value as a term, and a closed, first-order value pays for what a term can be: open, holed, a closure over an environment. The cost has come up again and again:
- Probe samples. A sample keeps, beside its value, the bindings its expression names, each value with the environment substituted into it (
Sample.Env.elide). On the Witch slide, the ⇓ toggle's probe on the program's last line, a closed, first-order tuple of a few bytes, kept theDrawingmodule that way: 3.8 MB of the worker's 5.4 MB answer (^report(46), what the answer holds). With function-holding values left out, the answer was 0.42 MB, most of it the picture written out again in four samples, each copy fresh (two cuts). - The trip between the worker and the page. Encoding a term with every node's ids, then a hash of every node to share what the page held, then decoding it: 70% of a small edit on that slide (the trip), and the sharing cost more than it saved once the answer was small; it is gone from the answers (Matthew: "drop sharing").
- hazel-jit. A compiled view's model goes into JS, and its answer came back as terms: the way back was most of a compiled render, and making ids for it a large part (
^report(45)). - Before that.
^ticket(666), how much sharing is lost passing data to and from the worker;^ticket(681), JS values converted directly at the call boundary;^ticket(710), lists as trees;^ticket(513), the sharing itself; and the note inCachedStatics.compute_targets, where samples' environment copies were once about 80% of retained memory.
Dev pays more than the branches measured there. Its worker's answer is the run's value and final state as they are: not pruned, with the observation trace, and with the whole incremental cache, which goes to the page and comes back with the next request (WorkerServer.Request.value.prev).
The form#
A new value form in the core language: Data, a closed, first-order value with nothing inside it but data. Dev has no type of values apart from terms: a value is a term that ValueChecker calls a Value. So the special case is a term:
/* Grammar.exp_term, beside Atom, ListLit, Tuple, Constructor, ... */
| Data(Data.t)
/* Data.re */
type t =
| Atom(Atom.t) /* Int, SInt, Nat, Float, Bool, String: the term's own atoms */
| List(list(t))
| Tuple(list(field)) /* labeled or not; () is Tuple([]) */
| Ctor(string, option(t)) /* a constructor, alone or applied */
and field = {
label: option(string),
value: t,
};
- No source ids. A value has none: not below the
Datanode, and not on it, whose tag is one shared, empty tag, not a fresh id per value. Which code made a value is kept beside it (below). (Matthew, 2026-11-08: "IMO -- Values should not have source ids. That makes very little sense. That association should be stored elsewhere --- like a global DCG, in the case of Fumola.") - Nothing inside but data. No holes, no closures, no environments, no ascriptions. So it is closed: substitution passes over it without a walk, and a probe sample keeps it as it is.
- Made only by the evaluator. The user's syntax has no way to write it, and the statics never see it in a program; only values are ever data.
- Types. A term's constructor carries its type for the statics of results (
Constructor(string, option(option(typ)))). Data does not, below its root: theDatanode can carry the value's type once, where the evaluator knows it, and turning data back into a term reads the constructors' types from it. - Big numbers.
Atom.tas dev has it:IntandNatare big integers,SInta machine one.
Beside Fumola's Value#
Fumola keeps its values apart from its terms, and each first-order case of its Value is plain data that serializes and deserializes as it is. The cases proposed here are those cases, inside Hazel's terms. (Matthew, 2026-11-08: "For comparison --- Fumola has a Value type. Each first-order case of Value (most of them) is simple to serialize and deserialize.")
- Fumola's
Value(crates/fumola_semantics/src/lib/value.rs, atcb2bcf5):Null,Bool,Unit,NatandInt(big),Float,Char,Text,Blob,Array,Tuple,Object,Option,Variant(a name and an optional value); then the cases that are not data: pointers, closed functions, primitive functions, modules, quoted code, actors, Adapton's pointers, times, spaces and histories, thunks. Every case derives serde'sSerializeandDeserialize; the first-order ones need nothing more, and values come in from JSON as they are (fumola_define_json, #148 in the Fumola repo). - No ids in a value. The program's ids are in its terms, and a value is not a term, so a value carries none: the cost Hazel's terms pay at every node is not there to pay. Which code made a value is in the run's graph (below).
- No sharing written. Arrays and tuples are persistent vectors (
im-rc), shared by reference in memory and cheap to grow and index; serde writes a shared value where it is met, as a tree. That is what Matthew expects of data here. - What Hazel's form takes from it. The same shape:
Data'sAtom,List,TupleandCtorare Fumola's atoms,Array,TupleandObject, andVariant; no ids; each case encoded as it is; and the same line between data and the rest, closures on the other side. - What differs. In Hazel a value is a term, so that a result can hold holes and be stepped and printed as code. So
Datais a case of the term, made by the evaluator, not a separate type the evaluator returns. A separate value type, as Fumola has, every result a value and terms kept for holes and the stepper, is the larger alternative; it would change the evaluator and the stepper throughout, and is not proposed here.
Why it is cheap to send#
Three things a term costs to encode that data does not: its ids, a search for sharing, and boxed numbers. And data could skip encoding altogether.
- No ids. Every term node carries an id tag (
IdTagged.IdTag.t): its ids, each a 16-byte UUID, and the secondary runs, incomplete tiles and lexeme the editor keeps for a written term, empty for one the evaluator made, but there. A list of 1,000 numbers as terms is about 1,000 cons blocks, 1,000 term records, 1,000 id tags with their id lists and UUIDs; as data, 1,000 cons blocks and the numbers. - No sharing to find.
Marshalkeeps a table of every block it has written, so that a block met twice is written once; for terms with environments that is needed. Data is not expected to share (Matthew, 2026-11-08: "in first order data --- we don't expect any"), so it can be written as a tree, with no table:Marshal'sNo_sharing, or an encoder of its own. - Numbers packed. An encoder of its own can write a list of floats as one array of floats: the Witch's 924 points are 1,848 numbers, about 15 KB as doubles, against about 0.13 MB for the picture as terms (an estimate from
^report(46)'s readings, not measured). - Or not encoded at all. Data turned into plain JS values (arrays, numbers, strings) crosses
postMessageby the browser's own structured copy, in native code, with noMarshalin js_of_ocaml on either side. The browser's copy recurses: it overflowed on deep terms (#2368), so a long list would cross as an array, its depth that of the data's nesting, not its length. A message would then be its terms, encoded as now, and beside them the data, as JS values.
Which of these to build first is a measurement: the first slice times each on the answers it changes.
Which code made a value: kept beside it#
A value carries no source ids; the association between a value and the code that made it is kept elsewhere, keyed by the code's id. Hazel already keeps most of it that way.
- Already beside the value. A probe's samples are keyed by the probed expression's id (
Sample.Map: a syntax id to its samples); a test's reports by the test's id (TestMap); the observation trace names the code of each span it opens and closes; a livelit's model is found by the model's id in the samples. - In Fumola, a global graph. In Fumola's graphical mode, a run's demanded computation graph names each node by a symbol and a time and records its thunk and the value it holds; asking which code made a value is a question for the graph, not for the value.
- What reads a value's ids on dev today (added 11-08, 10:27; a read of dev at
782249bbd0, its four key points checked by hand): about 30 places in 8 groups, and none maps a first-order value back to its source. The run's final value already has none:Evaluator.finishgives every node of it a fresh id (Exp.replace_all_ids). Source ids reach values by copying, not by design: a value built by a rule keeps the annotation of the code it came from, so probe samples and their environments carry source ids, and a looked-up variable's value gets a fresh one (fast_copy(Id.mk())).- Works as it is, or better without ids: the evaluator's own reads (the id of the term about to be evaluated: probe targets, reuse checks, the incremental cache; ids on values there are a hazard the code already guards against); ids copied through casts, which nothing reads in the value case; equality and hashing, which ignore ids; the worker, which only carries them; samples matched to projectors, already keyed by the code's id.
- Code, not data: the one link from a runtime value back to source, a call-stack frame's function definition, comes from a closure's function, which the data form leaves alone; tests and theorems are keyed by their own term's id.
- The real work: two readers that type a sample by running statics on it and looking up the value's own id (
DynamicTypInfer.type_of_sample,TableTransforms.get_dynamic_type): they need a typer for data, or a term made from the data with fresh ids. And printing (every probe chip and result view, throughExpToSegment) and the stepper, which need values as terms with unique ids, not source ids: one conversion from data to a term, shared.
- Where the evaluator mints ids for values, the cost a data form removes: the final value re-identified whole; every variable lookup; terms the rules build (a closure, an application, a list's cons and concatenation, a tuple's extension); every
x :: xsmatch on a list literal, for the tail; one ascription per element when a type is pushed through a value; every substituted value in a sample's environment; builtins' results; and the stepper, the whole program at every step.
When a value becomes data#
First where a value leaves the evaluator; then in the evaluator itself.
- At the edges. A check,
Data.of_term : Exp.t => option(Data.t), walks a value and gives up at the first function, closure, hole or open term;Data.to_termmakes the term back, with fresh ids, only when something needs a term (a probe's drawer prints a term today). Where the statics know the value's type, a first-order type (no arrows, nothing unknown:Typ.has_fun_up_to_aliasesand its like) says so before the walk. - In the evaluator. A tuple, list or constructor whose parts are all data is made as data, so values stay data as they are built, and are never turned into data at the edges. Then pattern matching, the builtins on lists and numbers, equality and printing read data directly: a match of
hd :: tlagainstData(List([a, ...rest]))bindshdtoaandtltoData(List(rest)). This is the larger change, and the one that keeps values from ever being terms.
Where it pays, in order#
- Probe samples (dev). A sample's value, and each binding in its environment, is data, or opaque (a function, or a value holding one), or, only when it is open, a term. The drawer turns data into a term when it draws it, once per sample shown. This fixes the Witch's case at its root, and every probe on dev with it.
- The worker's messages (dev). The program's value, the samples, and the incremental cache's states, in both directions, carry data; measured as bytes and as encode and decode time on each side.
- Livelit models (the livelits branches, then dev when they land). A model is first-order by design, written into the program as a literal: data from the start, and each livelit's samples with it.
- hazel-jit (
^report(45)). Data into JS and back, directly: arrays, numbers, strings, with no term made on the way back;^ticket(681)'s idea, and the diffs of^ticket(715)on data.^ticket(710)'s lists as trees would be a change toData.List, not to every term. - The evaluator (above): values built as data.
What it costs#
- A second form wherever values are read: the matcher, the builtins, equality (a data value against the same value as a term), printing,
ValueChecker, the probes' drawers and their custom renderers (about ten places readsample.valueinProbeProjon dev). The edges come first because they need onlyof_termandto_term. - The same answers both ways. Tests:
to_term(of_term(v))equal tovup to ids for every value the test programs make; and every program's results, probes and tests the same with data on and off. - No sharing. A value held twice is written twice. Matthew does not expect data to share; a message that grows because of it would show in the measurements.
- Floats.
Atom.tcompares floats by their printed form; data keeps that.
What it is not#
Not a change to holes or to open terms: anything that is not closed, first-order data stays a term, and behaves as it does now. No closures in data, and no holes; no sharing; no types below the root. Programs, and the editor's terms, are untouched: only values can be data.
The experiments#
Before a plan goes to the group, the same values measured each way: as Hazel's terms today, as the data form here, and as Fumola's values, which already work this way. Where things stand on the Witch slide (^report(46)): with a module kept out of a probe's environment, the trace cleared and the answers unshared, a small edit takes 1.3 to 1.7 s, and the worker's evaluator is 0.81 to 0.92 s of it, 50 to 64%; the trip is 5 to 8% (two cuts, and sharing dropped). So the evaluator, building values as terms, is now the larger cost, and sending them the smaller.
- Sending. Done 11-08 (below). The Witch's picture (133 shapes, 924 points,
046/data/witch/picture.json) and a probe-heavy answer, encoded and decoded: as Hazel's terms byMarshal(today); as data byMarshalwith no sharing table; as data packed (numbers in float arrays); as plain JS values by the browser's structured copy; and as Fumola'sValuethrough serde (its JSON door, and a binary form). Bytes, and ms each way, in Node and in Firefox. - Building. A first slice done 11-08 (below): the picture's nodes built three ways, outside a run, as a ceiling. It puts building values as data at a couple of percent of a run at most, so on this evidence a prototype evaluator would cost more than it could save. The picture built by each evaluator: Hazel's today (terms, a fresh id per node); Hazel's with a prototype of the data form (values built as data); Fumola's. Time, and blocks allocated.
^report(29)already set the two evaluators side by side on eight small programs: Hazel took half Fumola's steps, and each cost about 20 times as much: 2.6 µs a pass against 0.13 µs a step. (Corrected 11-08, 08:33: this said about 15 times, from^report(29)'s series card; its text says about 20.) - Ids. Done 11-08 (below). How many fresh ids a run makes on the Witch slide, and what making them costs (
^report(45)measured one id at a time; in^report(29)'s profiles, fresh ids were 46% of one program's time); the first count of what reads a value's ids (above). - Reading. Done 11-08 (below). A probe's drawer printing a sample: a term today; data turned into a term; data printed directly.
- Into JS. Done 11-08 (below), hazel-jit's trip in and Fumola's through
fumola_wasm. The picture into a compiled view: from Hazel's terms (hazel-jit's trip in,^report(45)), from data, and from Fumola's values throughfumola_wasm.
Where they run: Hazel's in Node on GitHub's machines (the test build is too heavy for the laptop) and in the Firefox check; Fumola's on the laptop, from its own repo (a cold build is about 3 minutes). Each result goes into this report as it comes, with its commit and run.
Experiment 1: sending the Witch's picture#
As data, the Witch's picture is 3.0 times smaller than as Hazel's terms (48.0 KB against 142.2 KB), and its trip by Marshal, encoded and decoded, takes 4.38 to 7.28 ms against 15.0 to 25.7, 2.5 to 4.3 times less. As plain JS values it would cross by the browser's own copy in 0.58 to 1.09 ms, once made JS (0.61 to 0.81 ms), or as JSON in 0.54 to 1.28 ms both ways. Fumola, natively, reads the same picture from JSON into its Value in 1.04 ms.
| The Witch's picture, sent as | KB | encode, ms | decode, ms | |
|---|---|---|---|---|
Hazel's term, by Marshal (today) | 142.2 | 9.67 to 12.0 | 4.00 to 14.3 | |
data, by Marshal | 48.0 | 3.12 to 5.20 | 1.25 to 2.08 | |
data, by Marshal with no sharing table | 62.0 | 1.79 to 3.86 | larger: a string met twice is written twice | |
data made plain JS values, by structuredClone | 0.61 to 0.81 (made JS) + 0.58 to 1.09 (the copy) | what postMessage does with JS values | ||
| data made plain JS values, as JSON | 66.3 | 0.61 to 0.81 (made JS) + 0.33 to 0.81 | 0.21 to 0.47 | |
Fumola's Value, from JSON (json_in) | 44.3 | 1.04 | native, on the laptop | |
Fumola's Value, through its serde derive (JSON) | 113.8 | 0.27 | 0.99 | native, on the laptop; tagged, so wordier |
Times in Firefox are ranges over the check's runs (42493347395, 42494174912, 42494936942, 42495801262); Firefox's clock there ticks in whole milliseconds, and each time is the median of five batches of at least 25 ms.
- What was measured. In the page, from the last answer the worker sent on the Witch slide after a slider's step: the picture, the probe sample with the most nodes as data (5,636), sent each way (
DataExperiment, ontrial/694-view-jit;480a30a8dd, run 42493347395, 42494174912, 42494936942, 42495801262). Every one of the answer's 108 samples converts to data (108): together 275.9 KB as terms, 144.7 KB as data. - No sharing table: larger, not faster. Data written with
Marshal'sNo_sharingis larger, because a string met twice (a shape's colour, its kind) is then written twice; and it is hardly faster to write. Data is not expected to share, but its strings do, by accident of the evaluator; an encoder of its own could keep a table of strings alone. - Making data from a term. The prototype turns a value term into data after the fact, in 0.83 to 2.54 ms for the picture. (The first version took 110 ms: it stripped the ascriptions of the whole subterm at every node, so it was quadratic. Matthew: "can we fix the quadratic cost?" It peels each node's own now.) In the evaluator's form, a value would be made as data and never converted.
- Fumola beside it (native, on the laptop, a release build;
^report(29)measured Fumola's wasm at 1.2 to 1.5 times its native time): the picture's JSON is 44.3 KB; read into aValuein 1.04 ms; written throughValue's own serde derive in 0.27 ms and read back in 0.99 ms (that form tags every case, so it is wordier than the plain JSON). Hazel's numbers are Firefox's on GitHub's machines; the two are not the same machine, so read the comparison to within a factor of two or so.
Where the bytes are: treemaps#
The picture's bytes as Hazel's terms and as data, drawn as treemaps: each rectangle's area is its bytes, each shape an outer rectangle split into what its bytes are. Treemaps are Ben Shneiderman's, from the University of Maryland's Human-Computer Interaction Lab (1991), made first to show where a disk's space goes; the layout here is the squarified one of Bruls, Huijsing and van Wijk (2000), which keeps rectangles near square so their sizes compare by eye. (Matthew, 2026-11-08: "I'd really like to see 'tree maps' as figures (2d, not 1d) ... for before and after the first-order representation is applied.")
Marshal sizes, taken shape by shape as each adds to the shapes before it, so the shapes add up to the whole and what they share (the types every constructor carries, a repeated string) is counted once, on the first shape that uses it (DataExperiment.tree). Firefox on GitHub's machines, run 42495801262 (480a30a8dd). Hover a rectangle for its bytes.As Hazel's terms, the picture's ids and tags are 55.8 KB of its 142.2 KB (39%); the rest of the terms' structure 38.4 KB; the data's own structure 32.2 KB; and the data itself, its numbers and strings, 15.8 KB, 11% of the whole. As data, only the last two are left: 48.0 KB. Each amount is a difference of two exact sizes: the term against the same term with every id tag one shared tag; that against the data; the data against its numbers and strings alone; each taken for the picture's 133 shapes in turn, as each adds to those before it. The first shape, the frame, carries the types every shape's constructor shares, so it is large as a term and nearly nothing as data.
Experiments 3, 4 and 5: ids, reading, and into JS#
Data pays most at the edges: printing the Witch's picture as data takes 1.83 to 2.03 ms against 91.8 to 110.3 ms as a term, 50 to 54 times less, and sending it 2.5 to 3.9 times less (experiment 1); carrying it into JS takes about the same either way (1.0 to 1.1 times). Inside the run, minting ids is a small part: a run mints 188,718 to 189,922 ids, 12 to 14 ns each, about 2.2 to 2.6 ms, 0.2 to 0.3% of the evaluator's 0.84 to 1.00 s. (Matthew, 2026-11-08: "push on this".) The same check as experiment 1, on the Witch slide's small edits: the id counts from run 42504537594 (e69234eb95), the times from runs 42536466518, 42537027939 (e1967c3a40), each the median of five batches of at least 300 ms. (Corrected 11-08, 16:58: this section first gave an id as 157 ns to mint, so minting 3.0 to 3.6% of the evaluator, and the trip into JS as 1.4 times quicker from data. Those were timed in batches of 25 ms, which one garbage collection of the page's heap can fill, and two later runs timed that way disagreed by up to five times (experiment 2). Timed in batches of at least 300 ms, an id is 12 to 14 ns, minting is 0.2 to 0.3% of the evaluator, and into JS is about the same either way. Printing held: 50 to 54 times quicker as data, 38 before.)
- Ids (experiment 3).
Id.mkwrites its running count into every id it makes, so an id minted before a step and one after it tell how many were made in between, withId.mkuntouched (WorkerServer.id_count). Each run in the worker mints 188,718 to 189,922, the same number for the same edit every time; the page mints 3,109 to 3,111 for an edit with compiled views on, and up to 37,124 with them off, when the interpreter draws the picture's view anew. One id costs 12 to 14 ns to mint in the page. That is minting alone: each id's tag (a record and a list), the terms around it, and the garbage of all of it are not in that number, and with them, kept in a tree, an id costs 59 to 91 ns (experiment 2), a run's ids 1.0 to 2.5% of the evaluator. So taking ids out of values saves a couple of percent of the run; the run's larger costs are the evaluator's own (^report(29): its stages and trampolines, 37% of a loop). - Reading (experiment 4). The picture printed as a term, as the CLI prints a result and much as a probe's drawer does (
ExpToSegment, thenPrinter), takes 91.8 to 110.3 ms for 51.1 thousand characters; printed as data, 1.83 to 2.03 ms for 48.3 thousand. A probe on a value this size costs a frame's budget several times over just to show. - Into JS (experiment 5). hazel-jit's own conversion of the picture from a term into JS values (
HazelJitValue.to_js) takes 0.64 to 0.72 ms; from data, 0.60 to 0.71 ms: about the same. hazel-jit's trip in is already lean; reading past the term's records and tags costs it next to nothing. Fumola's side (11-08, Node on the laptop, three runs): throughfumola_wasm's doors the picture goes into an instance in 0.81 to 0.83 ms (fumola_define_json, from its 44.3 KB of JSON) and comes out to JS values in 9.25 to 9.43 ms: 8.23 to 8.39 ms to write it as the tagged JSON the Hazel side decodes, 160.1 KB with a tag on every node (value_to_json, building aserde_json::Valuetree, then its text), 0.75 to 0.78 ms for JS to parse that, and 0.27 to 0.28 ms the call costs on a constant. Fumola's values are cheap to hold and natively quick to write (0.27 ms through serde, experiment 1); its door to JS, as built for Hazel, is not. A different machine and engine from Hazel's numbers (Node on the laptop, Firefox on GitHub's), so the comparison is of shape: the door's own text costs more than either of Hazel's trips in. The script is047/data/exp_718_fumola_js.js; Fumola atcb2bcf5.
Experiment 2, a first slice: building the picture#
Building values as data would save the evaluator a couple of percent at most. Built node by node, the Witch's picture takes 0.94 to 1.34 ms as Hazel's terms with a fresh id on every node, 0.30 to 0.34 ms as terms with no id minted, and 0.31 to 1.38 ms as data, about what terms with no ids cost. An id with its tag, kept in a tree, costs 59 to 91 ns a node; a run mints 188,718 to 189,922, so 11 to 17 ms, 1.0 to 2.5% of the evaluator's 0.68 to 1.08 s. The evaluator's time is its own work, not the values it builds: to reach 60 fps the run itself has to be compiled (^ticket(722)). The same check, on the Witch slide (e1967c3a40; runs 42536466518, 42537027939), each time the median of five batches of at least 300 ms.
- What was built. The picture's 5,636 data nodes, rebuilt from its data three ways (
DataExperiment.build_termandbuild_data): as terms withExp.freshat every node, as the evaluator builds a value today; as terms withExp.temp, the one shared tag, so no id, no tag record and no list of ids; and as data. As a term the picture has 10,948 nodes, since a label and a constructor's name are nodes of their own. Per term node: 86 to 122 ns with a fresh id, 27 to 31 ns with none, 29 to 126 ns as data. - What an id costs. Minted and dropped in a loop, 12 to 14 ns. Kept in a tree with its tag (a 16-character JS string, a record and a one-element list), 59 to 91 ns more per node than a term with no id: what it allocates and keeps.
- The noise. The data build is the noisiest of the three: its batches ran from 0.17 to 1.93 ms, and the difference between data and terms with no ids is lost in that. Against today's terms, building as data saves at most 11 ms of a run, 1.6% of the evaluator, and in one of the two runs nothing.
- Why even that is high. The run mints one id for each term it rebuilds and each environment binding; the numbers above count each as a node built and kept, as the picture's are. Many of a run's terms die young, which costs less.
(Before publishing, 11-08: a first draft of this experiment put the ceiling at 17 to 36% of the evaluator. It was timed in batches of 25 ms, and a second run of the same commit timed terms with no ids as 3 times slower than with fresh ids, which no cost explains: a 25 ms batch is shorter than one garbage collection of the page's heap, so a batch holding one reads several times too slow (runs 42535123022, 42535708383). Experiments 2 to 5 are now timed in batches of at least 300 ms, which spreads a collection over the calls that cause it, and every batch's time is kept. Experiment 1's times were taken in 25 ms batches too; over its runs they agreed in direction, and they are next to be timed again.)
The plan for the group#
Written from the experiments, for the group: which form, which edges first, and what each costs and saves, as measured. What they say so far (11-08): the data form pays at the edges, 2.5 to 3.9 times quicker to send, 50 to 54 times quicker to print, and needs only one shared conversion back to a term on dev (what reads a value's ids); inside the evaluator, building values as data saves a couple of percent at most, ids and tags and all (experiment 2's first slice), so the 60 fps goal needs the run itself compiled (^ticket(722); ^report(46), compiling the run) or made incremental. The data form is for the edges: what the worker sends, and what the page prints.
At the edges it did what the experiments said, on the livelits branch (trial/694-view-jit, the Witch slide in Firefox, ^report(51), builds 19 and 20). Weighed by part, the worker's answer was 590 KB, 112 KB of it a final stream the page set aside on arrival, now not sent; the result's first-order sample values, 17 a result, its picture among them, now go as data and are made terms again in the page, and none has come back different. The answer is 198 KB; the worker's encoding 21 to 29 ms, from 72 to 107; the page's decoding 7 to 8 ms, from 24 to 31. What is new is the two conversions, as slices 2 and 3 below expect: 29 to 41 ms in the worker making the data, a check of each value's way back included, and 6 to 17 ms in the page making terms again. Both go when samples are made as data and the page draws data. The first try, on build 11, made the answer larger (0.89 MB): it rebuilt the samples of the 216 cached states its messages carried, and lost the sharing among them; with no final stream, only the result's own 108 samples are rebuilt. A draft of the slices:
Data,of_termandto_term, with the round-trip tests and the list of what reads a value's ids on dev (above), and a Node benchmark on dev: a program whose probes name a module and a list of a thousand records, its worker answer's bytes and its encode and decode time, as terms and as data (each way of sending, above).- Probe samples as data: the sample's value and environment; the drawer draws data. Measured with that benchmark and on dev's deploy in Firefox. (Tried at the edges on the livelits branch, above: made data where the answer is sent and terms where it arrives.)
- The worker's messages: the value and the cache's states, and the way of sending the first slice found fastest. (On the branch, results only: a result carries one state, and a stream's many cached states share their samples, which rebuilding them lost.)
- The
Dataterm in the evaluator: values built as data; the matcher, the builtins, equality and printing. - The livelits branches: models and livelit samples as data, and hazel-jit's trip; measured on the Witch's small edits (1.9 to 2.4 s when this note was begun, two cuts; on the branch now, a step shows in 19 to 24 ms with the run compiled, and the probes' answer is the edge left,
^report(51)).
Questions for Matthew#
- The name:
Data, or something else? - Lists: an OCaml list, cheap to cons; an array, cheap to send and to index; a persistent vector, as Fumola's arrays are; or a level tree, as
^ticket(710)asks? - Is the evaluator's form (slice 4) in scope from the start, or the edges first, as here? And is a separate value type, as Fumola has, worth weighing instead?
- Constructors' types: carried once at the root, as here, or not at all, the statics finding them again?
How this was put together#
- Dev as read:
782249bbd0(2026-11-06), in a worktree of its own: the expression terms (Grammar.exp_term),Atom.t,ValueChecker,Sample.Env.elide,CachedStatics.compute_targets,WorkerServer's request and answer, andProbeProj's reads of a sample's value. Fumola as read:cb2bcf5(2026-10-22),value.rsandfumola_wasm's JSON door. - The Witch's current numbers (1.3 to 1.7 s an edit) are
^report(46)'s, after the two cuts and the sharing dropped. The other numbers are^report(46)'s too, measured on the livelits line (trial/694-view-jit) in Firefox on GitHub's machines; none is measured on dev yet. The 15 KB for the Witch's points is arithmetic, not a measurement. - The numbers, for programs too: every table in this report, and what its numbers measure, is also in this page as JSON, in its
<script type="application/json" id="report-data">element, so a reader or an agent that fetches the page alone has the dataset. The same, with any raw files that survive, is in047/data/.