Hazel reports · ^report(60) · Hazel’s speed · 2026-11-20, revised 2026-11-20 14:01 MST · work in progress · after ^report(54)

How Fast Is Hazel? Five Games, Three Ways

Cyrus asked how fast Hazel is: interpreted, compiled by hazel-jit, and against plain JavaScript. Five games from the Hazel activities answer it here. Each game’s rules and strategy are a Hazel program, run three ways: interpreted by hazeljs, compiled ahead of time by hazel-jit, and rewritten in plain JavaScript, a version written to give the same answers in the same order. All three are timed on one machine, operation by operation and over whole games that Hazel plays against itself.

3,257×
hazel-jit over hazeljs: the compiled Hazel against the interpreter
13×
plain JavaScript over hazel-jit: the same game written in JavaScript
44,642×
plain JavaScript over hazeljs

Geometric means over the five games of each game’s own geometric mean over its operations, measured in Node on one GitHub runner (how). The spread inside each game is wide: see the figures.

Outline#

  1. Every operation, three ways: the 39 operations of the five games, on one scale.
  2. How much faster, game by game: compiled over interpreted, and plain JavaScript over compiled.
  3. Where hazel-jit’s time goes: its step budget, its exact integers, the page boundary, and the shape of the program itself.
  4. What hazel-jit’s code pays over plain JavaScript: the overheads one by one, each with its own link: what it is, an example, whether it is measured, and what would remove it.
  5. The games, one by one: each strategy, where randomness enters it, what its work grows with, and its numbers.
  6. The same answers, three ways: how we know the three versions play the same game.
  7. What next, and how this was put together.

Every operation, three ways#

Compiled by hazel-jit, the five games’ rules run about 3,300 times as fast as hazeljs interprets them; written in plain JavaScript, the same games run about 13 times as fast again. So plain JavaScript is about 45,000 times as fast as Hazel’s interpreter on these games, and hazel-jit closes all but a factor of about 13 of that distance. Operation by operation the factors spread: compiled over interpreted from 841× (opening a cell on an expert Minesweeper board) to 10,082× (listing Solitaire’s legal moves), and plain JavaScript over compiled from 2× (dealing a Mahjong hand) to 137× (opening that Minesweeper cell).

hazeljs, interpreting the Hazel (build 1) hazel-jit, the Hazel compiled (build 2) plain JavaScript (build 3)

Every operation of the five games, timed three ways: hazeljs, hazel-jit, plain JavaScript; a log scale from 0.1 microseconds to 100 seconds0.1 µs1 µs10 µs0.1 ms1 ms10 ms0.1 s1 s10 s100 sSolitairea deal · a new gamea deal · a new game: hazeljs 71 msa deal · a new game: hazel-jit 0.013 msa deal · a new game: plain JS 2.29 µsevery legal move · 25 moves inevery legal move · 25 moves in: hazeljs 160 msevery legal move · 25 moves in: hazel-jit 0.016 msevery legal move · 25 moves in: plain JS 0.931 µsa move made · 25 moves ina move made · 25 moves in: hazeljs 11 msa move made · 25 moves in: hazel-jit 7.34 µsa move made · 25 moves in: plain JS 0.194 µsthe moves from a pile · 25 moves inthe moves from a pile · 25 moves in: hazeljs 11 msthe moves from a pile · 25 moves in: hazel-jit 4.54 µsthe moves from a pile · 25 moves in: plain JS 0.075 µsMinesweeperthe mines laid · beginner, 9 by 9the mines laid · beginner, 9 by 9: hazeljs 83 msthe mines laid · beginner, 9 by 9: hazel-jit 0.028 msthe mines laid · beginner, 9 by 9: plain JS 2.64 µsa cell opened · beginner, 9 by 9a cell opened · beginner, 9 by 9: hazeljs 7.6 msa cell opened · beginner, 9 by 9: hazel-jit 7.61 µsa cell opened · beginner, 9 by 9: plain JS 0.121 µsthe hint (a sure move) · beginner, 9 by 9the hint (a sure move) · beginner, 9 by 9: hazeljs 122 msthe hint (a sure move) · beginner, 9 by 9: hazel-jit 0.031 msthe hint (a sure move) · beginner, 9 by 9: plain JS 4.31 µsthe mines laid · intermediate, 16 by 16the mines laid · intermediate, 16 by 16: hazeljs 290 msthe mines laid · intermediate, 16 by 16: hazel-jit 0.090 msthe mines laid · intermediate, 16 by 16: plain JS 8.85 µsa cell opened · intermediate, 16 by 16a cell opened · intermediate, 16 by 16: hazeljs 20 msa cell opened · intermediate, 16 by 16: hazel-jit 0.022 msa cell opened · intermediate, 16 by 16: plain JS 0.219 µsthe hint (a sure move) · intermediate, 16 by 16the hint (a sure move) · intermediate, 16 by 16: hazeljs 363 msthe hint (a sure move) · intermediate, 16 by 16: hazel-jit 0.133 msthe hint (a sure move) · intermediate, 16 by 16: plain JS 8.66 µsthe mines laid · expert, 16 by 30the mines laid · expert, 16 by 30: hazeljs 504 msthe mines laid · expert, 16 by 30: hazel-jit 0.173 msthe mines laid · expert, 16 by 30: plain JS 0.017 msa cell opened · expert, 16 by 30a cell opened · expert, 16 by 30: hazeljs 39 msa cell opened · expert, 16 by 30: hazel-jit 0.046 msa cell opened · expert, 16 by 30: plain JS 0.336 µsthe hint (a sure move) · expert, 16 by 30the hint (a sure move) · expert, 16 by 30: hazeljs 583 msthe hint (a sure move) · expert, 16 by 30: hazel-jit 0.227 msthe hint (a sure move) · expert, 16 by 30: plain JS 5.11 µsGoa move played · 6 moves ina move played · 6 moves in: hazeljs 17 msa move played · 6 moves in: hazel-jit 4.49 µsa move played · 6 moves in: plain JS 1.47 µsHazel's choice of move · 6 moves inHazel's choice of move · 6 moves in: hazeljs 588 msHazel's choice of move · 6 moves in: hazel-jit 0.105 msHazel's choice of move · 6 moves in: plain JS 7.63 µsthe score · 6 moves inthe score · 6 moves in: hazeljs 755 msthe score · 6 moves in: hazel-jit 0.138 msthe score · 6 moves in: plain JS 5.69 µsa move played · 40 moves ina move played · 40 moves in: hazeljs 188 msa move played · 40 moves in: hazel-jit 0.029 msa move played · 40 moves in: plain JS 3.89 µsHazel's choice of move · 40 moves inHazel's choice of move · 40 moves in: hazeljs 913 msHazel's choice of move · 40 moves in: hazel-jit 0.162 msHazel's choice of move · 40 moves in: plain JS 0.016 msthe score · 40 moves inthe score · 40 moves in: hazeljs 260 msthe score · 40 moves in: hazel-jit 0.048 msthe score · 40 moves in: plain JS 3.71 µsCheckersthe moves · the startthe moves · the start: hazeljs 37 msthe moves · the start: hazel-jit 0.012 msthe moves · the start: plain JS 0.572 µsthe moves · 8 moves inthe moves · 8 moves in: hazeljs 37 msthe moves · 8 moves in: hazel-jit 0.012 msthe moves · 8 moves in: plain JS 0.607 µsthe moves · 30 moves inthe moves · 30 moves in: hazeljs 27 msthe moves · 30 moves in: hazel-jit 9.09 µsthe moves · 30 moves in: plain JS 0.569 µsHazel's move, looking 1 ahead · 8 moves inHazel's move, looking 1 ahead · 8 moves in: hazeljs 130 msHazel's move, looking 1 ahead · 8 moves in: hazel-jit 0.046 msHazel's move, looking 1 ahead · 8 moves in: plain JS 1.75 µsHazel's move, looking 1 ahead · 30 moves inHazel's move, looking 1 ahead · 30 moves in: hazeljs 109 msHazel's move, looking 1 ahead · 30 moves in: hazel-jit 0.039 msHazel's move, looking 1 ahead · 30 moves in: plain JS 1.55 µsHazel's move, looking 2 ahead · 8 moves inHazel's move, looking 2 ahead · 8 moves in: hazeljs 635 msHazel's move, looking 2 ahead · 8 moves in: hazel-jit 0.226 msHazel's move, looking 2 ahead · 8 moves in: plain JS 0.013 msHazel's move, looking 2 ahead · 30 moves inHazel's move, looking 2 ahead · 30 moves in: hazeljs 498 msHazel's move, looking 2 ahead · 30 moves in: hazel-jit 0.180 msHazel's move, looking 2 ahead · 30 moves in: plain JS 0.010 msHazel's move, looking 3 ahead · 8 moves inHazel's move, looking 3 ahead · 8 moves in: hazeljs 2.12 sHazel's move, looking 3 ahead · 8 moves in: hazel-jit 0.729 msHazel's move, looking 3 ahead · 8 moves in: plain JS 0.045 msHazel's move, looking 3 ahead · 30 moves inHazel's move, looking 3 ahead · 30 moves in: hazeljs 1.86 sHazel's move, looking 3 ahead · 30 moves in: hazel-jit 0.649 msHazel's move, looking 3 ahead · 30 moves in: plain JS 0.044 msHazel's move, looking 4 ahead · 8 moves inHazel's move, looking 4 ahead · 8 moves in: hazeljs 6.20 sHazel's move, looking 4 ahead · 8 moves in: hazel-jit 2.2 msHazel's move, looking 4 ahead · 8 moves in: plain JS 0.139 msHazel's move, looking 4 ahead · 30 moves inHazel's move, looking 4 ahead · 30 moves in: hazel-jit 2.3 msHazel's move, looking 4 ahead · 30 moves in: plain JS 0.156 msHazel's move, looking 5 ahead · 8 moves inHazel's move, looking 5 ahead · 8 moves in: hazel-jit 6.1 msHazel's move, looking 5 ahead · 8 moves in: plain JS 0.428 msHazel's move, looking 5 ahead · 30 moves inHazel's move, looking 5 ahead · 30 moves in: hazel-jit 6.9 msHazel's move, looking 5 ahead · 30 moves in: plain JS 0.407 msHazel's move, looking 6 ahead · 8 moves inHazel's move, looking 6 ahead · 8 moves in: hazel-jit 19 msHazel's move, looking 6 ahead · 8 moves in: plain JS 1.5 msHazel's move, looking 6 ahead · 30 moves inHazel's move, looking 6 ahead · 30 moves in: hazel-jit 20 msHazel's move, looking 6 ahead · 30 moves in: plain JS 1.6 msMahjonga hand dealt · the first handa hand dealt · the first hand: hazeljs 180 msa hand dealt · the first hand: hazel-jit 0.042 msa hand dealt · the first hand: plain JS 0.021 msa Hazel player's turn (a step) · early in the handa Hazel player's turn (a step) · early in the hand: hazeljs 63 msa Hazel player's turn (a step) · early in the hand: hazel-jit 0.023 msa Hazel player's turn (a step) · early in the hand: plain JS 2.34 µsyour options · your turnyour options · your turn: hazeljs 28 msyour options · your turn: hazel-jit 9.39 µsyour options · your turn: plain JS 1.60 µsyour turn, played by Hazel (a step) · your turnyour turn, played by Hazel (a step) · your turn: hazeljs 62 msyour turn, played by Hazel (a step) · your turn: hazel-jit 0.019 msyour turn, played by Hazel (a step) · your turn: plain JS 2.46 µsthe claims on a discard (a step) · another's discardthe claims on a discard (a step) · another's discard: hazeljs 60 msthe claims on a discard (a step) · another's discard: hazel-jit 0.021 msthe claims on a discard (a step) · another's discard: plain JS 8.80 µs
Builds 1, 2 and 3 (named in How this was put together): each operation’s median time per call, on a log scale where each grid line is ten times the one before. Hover over a mark for its time. Measured in Node 22, not in a browser. An empty row for hazeljs means it was not timed there: a call would take too long (Checkers looking 5 or 6 moves ahead, whole expert boards).

How much faster, game by game#

Compiled over interpreted varies little between the games, from about 2,000× (Minesweeper) to 5,300× (Go); plain JavaScript over compiled varies much more, from 4.6× (Mahjong) to 26× (Minesweeper). Interpreting costs about the same per step of work in every game, so compiling gains about the same everywhere. How much more plain JavaScript gains depends on what each program does with its data: least where the work is small lists copied as they change, as Mahjong’s tiles are, most where a JavaScript array or bit operation replaces a walk along a list, as on a Minesweeper board (where hazel-jit’s time goes).

Per game, how many times faster: hazel-jit than hazeljs, and plain JavaScript than hazel-jit (geometric means over the game's operations)1×10×100×1,000×10,000×SolitaireSolitaire: hazel-jit over hazeljs, 3,665×3,665× hazel-jit over hazeljsSolitaire: plain JS over hazel-jit, 22×22× plain JS over hazel-jitMinesweeperMinesweeper: hazel-jit over hazeljs, 2,037×2,037× hazel-jit over hazeljsMinesweeper: plain JS over hazel-jit, 25×25× plain JS over hazel-jitGoGo: hazel-jit over hazeljs, 5,345×5,345× hazel-jit over hazeljsGo: plain JS over hazel-jit, 10×10× plain JS over hazel-jitCheckersCheckers: hazel-jit over hazeljs, 2,881×2,881× hazel-jit over hazeljsCheckers: plain JS over hazel-jit, 17×17× plain JS over hazel-jitMahjongMahjong: hazel-jit over hazeljs, 3,186×3,186× hazel-jit over hazeljsMahjong: plain JS over hazel-jit, 4.6×4.6× plain JS over hazel-jit
Builds 1, 2 and 3: for each game, the geometric mean over its operations of hazeljs’s time ÷ hazel-jit’s (orange) and hazel-jit’s ÷ plain JavaScript’s (aqua), on a log scale. Each game’s table, under The games, has every operation’s own ratio.

Where hazel-jit’s time goes#

Taking out hazel-jit’s step budget, and making its arithmetic plain, saves at most about a quarter of its time: most of the distance to plain JavaScript is elsewhere. Without the step check in every function, the games ran in 0.76 (Mahjong) to 1.04 (Checkers, within the noise) of hazel-jit’s time; with plain-number arithmetic as well, in 0.77 to 0.91.

hazel-jit's time with its step budget taken out, and with plain-number arithmetic too, as a share of hazel-jit's own time (1.0), per game00.250.50.7511.25SolitaireSolitaire: no step budget, 0.92 of hazel-jit's time0.92 · no step budgetSolitaire: and plain numbers, 0.91 of hazel-jit's time0.91 · and plain numbersMinesweeperMinesweeper: no step budget, 0.95 of hazel-jit's time0.95 · no step budgetMinesweeper: and plain numbers, 0.87 of hazel-jit's time0.87 · and plain numbersGoGo: no step budget, 0.89 of hazel-jit's time0.89 · no step budgetGo: and plain numbers, 0.83 of hazel-jit's time0.83 · and plain numbersCheckersCheckers: no step budget, 1.04 of hazel-jit's time1.04 · no step budgetCheckers: and plain numbers, 0.83 of hazel-jit's time0.83 · and plain numbersMahjongMahjong: no step budget, 0.76 of hazel-jit's time0.76 · no step budgetMahjong: and plain numbers, 0.77 of hazel-jit's time0.77 · and plain numbers
Builds 2a and 2b against build 2: each game’s geometric mean, over its operations, of a variant’s time ÷ hazel-jit’s own (1.0, dashed). Below 1, the variant is faster. Both variants are made from compiled.js only for this measurement. The answers stay the same, as each table row checks.

Every compiled function starts by counting a step. hazel-jit keeps the interpreter’s step limit: each compiled function begins with if (--$R.fuel < 0 || (($R.fuel & 16383) === 0 && performance.now() > $R.deadline)) $R.out();, so a run that loops can be stopped, as the interpreter’s can (^report(54)). Build 2a takes that line out of every function.

Every +, -, * and / on Hazel’s Ints is a call into hazel-jit’s runtime. $R.iadd, $R.isub, $R.imul and $R.idiv keep Hazel’s integers exact past 253, where JavaScript’s numbers stop being exact, by switching to a BigInt there, as the interpreter’s integers are exact (^ticket(757)). Build 2b replaces them with plain number arithmetic, which these games can stand: their numbers stay far below 253.

Most of the rest is the program’s shape: what Hazel gives a program to compute with, and how hazel-jit passes values around. Hazel has lists and no arrays, numbers and no bit operations, and no way to change a value in place. So the Hazel finds the stone at a point of the Go board by walking the rows to its row and along it; tests whether a Checkers square is in a set by dividing the set by a power of two, a power it finds by comparisons; and changes one cell of a Minesweeper board by building a new row and a new list of rows. The plain JavaScript indexes an array, shifts a number, and copies only what changed. hazel-jit adds costs of its own: every function takes one argument, so a call with two makes an array to hold them (has$16([b$19, k$20])), and every labeled tuple is an array whose labels are then set on it as properties, one by one ($R.tup). Removing those would take a compiler change, not a text replacement, so this report does not measure them apart (What next, steps 2 and 3).

Converting the game between the page’s values and hazel-jit’s, on every call, costs little for a game made of a few numbers, and a lot for a big board: 0.2 µs for Checkers, 40 µs for an expert Minesweeper board, most of the 46 µs that opening one of its cells costs compiled. The page holds the game as hazeljs gives it, JavaScript arrays and objects; hazel-jit’s code holds lists as chains of {h, t} cells and labeled tuples as arrays carrying their labels. compiled.js’s adapters convert the whole game in, and the answer out, on every call (the boundary’s own rows in each game’s table). Opening a Minesweeper cell, where plain JavaScript is 137 times as fast, is mostly this: the board, 480 cells of four fields each, built twice for one cell’s change.

What hazel-jit’s code pays over plain JavaScript#

Twelve things the compiled code does that the plain JavaScript does not: seven are hazel-jit’s, in the code it writes for any Hazel program; four are Hazel’s, in what a program can say; and one is the page’s, at the boundary between them. Three are measured here (the step budget, exact integers with their division, and the boundary); the others are named from the compiled code, with what would remove each. Each item has its own link.

The examples are from checkers/compiled.js (build 2, d15466c7b1), as hazel-jit wrote them.

In the code hazel-jit writes#

  1. A step counted at every call.# Every compiled function starts with if (--$R.fuel < 0 || (($R.fuel & 16383) === 0 && performance.now() > $R.deadline)) $R.out();: a decrement and a test on every call, and a read of the clock every 16,384 calls, so that a run that loops forever can be stopped, as the interpreter’s can. Measured (build 2a): without it, the games ran in 0.76 (Mahjong) to 1.04 (Checkers) of hazel-jit’s time. To remove: count steps only in functions that can call themselves, or check once per loop instead of once per call.
  2. Exact integers: every +, - and * a call.# a + b on Hazel’s Ints compiles to $R.iadd(a, b): a call that checks that both are numbers, adds, checks the sum is within ±253, and switches to a BigInt past that, so Hazel’s integers stay exact as the interpreter’s are. The plain JavaScript writes a + b. Measured with the next item and the step budget also out (build 2b): the games ran in 0.77 to 0.91 of hazel-jit’s time. To remove: plain arithmetic where hazel-jit can show the numbers stay small (a loop’s counter, a board’s index), with the exact path kept for the rest.
  3. Division with a zero check, and no remainder.# a / b compiles to $R.idiv(a, b): a check that b is not zero (Hazel reports dividing by zero as an error, and the compiled run must stop where the interpreter would), then (a - a % b) / b to round toward zero exactly. Hazel has no remainder operator, so the Checkers rules test a bit with q - (q / 2) * 2 == 1: four runtime calls ($R.idiv, $R.imul, $R.isub, $R.eq) where JavaScript writes q & 1. Measured with the item above, in build 2b.
  4. Equality as a call.# == compiles to $R.eq(a, b), a call that compares lists, tuples and constructors by their contents. For two numbers it returns at its first test (a === b), but the call is made every time. The plain JavaScript writes ===. Not measured apart. To remove: compile == on Ints, Bools and Strings, whose types hazel-jit knows, to ===.
  5. Every field read a call.# g.black compiles to $R.dot(g, "black"): a call that checks whether g is an array, reads the property, and, for a list, maps the read over its elements (Hazel lets a projection through a list read every row’s field). The Checkers rules make 48 such reads in their text, Mahjong’s 212, each a call every time it runs. The plain JavaScript reads g.black. Not measured apart. To remove: where the type says the value is a record (it does, everywhere in these games), read the property directly.
  6. A new array for every call’s arguments.# A Hazel function takes one argument, a tuple when it has several, so has(b, k) compiles to has$16([b$19, k$20]): an array made for the call, and read back out in the callee (a$18[0], a$18[1]). The plain JavaScript passes two parameters, and makes nothing. Not measured apart. To remove: compile a function whose argument is a tuple pattern to a JavaScript function of that many parameters (What next, step 3).
  7. Records built as arrays, then labelled.# A labeled tuple, such as Checkers’ (black = …, white = …, kings = …), compiles to $R.tup([…], ["black", "white", "kings", …]): an array whose labels are then set on it as properties, one by one. Every game value the rules return is built this way, a new one for each move. The plain JavaScript writes an object literal, which the engine builds in one step and keeps in one shape. Not measured apart. To remove: build a record as an object literal with its labels, and its positions where a program reads them.

In what a Hazel program can say#

  1. Lists, not arrays.# Hazel has lists and no arrays, and hazel-jit makes each list a chain of {h, t} cells. Reaching the n-th element walks n cells: the Go rules find the stone at a point by walking to its row and along it, about as many steps as the point is from the corner, where the plain JavaScript reads one array element. Building a list makes a cell for each element, and @ copies its left list ($R.append).
  2. A new copy for every change.# A Hazel value cannot be changed in place, so changing one Minesweeper cell builds a new row up to that cell and a new list of rows up to that row; every move in every game builds a new game. The plain JavaScript copies only what it must, and writes into its own copies.
  3. No bit operations.# Checkers keeps each side’s pieces as a 32-bit set, and Hazel has no shifts or masks, so the rules test a square by dividing the set by a power of two, which they find by comparisons (bit(k)), then take the remainder by hand (above). The plain JavaScript shifts and masks: (b >>> k) & 1.
  4. Helpers made again at every call.# A function defined inside another is a new closure each time the outer one runs. In hazeljs a module’s every top-level definition deepens the build’s stack, and a browser’s stack is short (^ticket(791)), so the games keep their helpers inside the functions that use them: Mahjong’s win_of makes its dozen helpers again on every call, and it is called for every seat at every discard. The plain JavaScript defines each helper once. hazel-jit could hoist a helper that uses none of its outer function’s variables.

At the page’s edge#

  1. The game converted in and out at every call.# The page holds the game as hazeljs gives it, JavaScript arrays and objects, and compiled.js’s adapters convert it to hazel-jit’s own values and the answer back, on every call. Measured on its own rows: 0.2 µs for Checkers’ few numbers, 1.4 µs for a Go board, 4 µs for a Solitaire game, and 40 µs for an expert Minesweeper board, most of the 46 µs that opening one of its cells costs compiled. The plain JavaScript works on the page’s own values. To remove: keep hazel-jit’s value of the game between calls and convert only what the page draws, or let hazel-jit take JavaScript arrays as its lists.

The games, one by one#

For each game: what the program decides, where randomness enters, what makes its work grow, and its numbers. Randomness in all five works the same way: Hazel has no random numbers of its own, so the page passes them in, a list of numbers drawn by JavaScript’s Math.random() as an argument. That makes every function a pure function of its arguments. Seeded numbers make whole games repeat exactly, which is how all three versions were timed playing the same games, move for move.

Solitaire (Klondike)#

Compiled, Solitaire’s rules run about 3,700 times as fast as interpreted, and plain JavaScript about 22 times as fast again: listing every legal move takes 160 ms interpreted, 16 µs compiled, 0.9 µs in plain JavaScript.

The program. Three modules (Cards, Deal, Moves; 244 lines with its vocabulary): the deck, the deal, every legal move in a fixed order, a move made, and the win. There is no opponent: the program’s work is the rules.

Randomness. Only the deal: 52 numbers from the page, each taking a card from those left at the place it falls. Every move after the deal is the player’s.

What the work grows with. Listing every legal move tries each card that can move against each of the seven piles and its foundation: the waste’s top card, each run of face-up cards in each pile, and each foundation’s top card, so about (1 + the face-up cards) × 8 checks. The Hazel walks lists to reach the n-th pile or foundation. The deal takes each card from the list of those left, walking it to the card’s place.

OperationPositionhazeljshazel-jitno step budgetand plain numbersplain JShazeljs ÷ hazel-jithazel-jit ÷ plain JS
a deala new game71 ms0.013 ms0.013 ms0.012 ms2.29 µs5,317×5.8×
every legal move25 moves in160 ms0.016 ms0.015 ms0.015 ms0.931 µs10,082×17×
a move made25 moves in11 ms7.34 µs6.42 µs6.40 µs0.194 µs1,450×38×
the moves from a pile25 moves in11 ms4.54 µs4.25 µs4.30 µs0.075 µs2,322×60×
the page boundary: the game in and out25 moves in—4.09 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
Whole gameMoveshazeljshazel-jitno step budgetand plain numbersplain JSSame end
300 random moves30066.2 s9.4 ms9.5 ms9.2 ms1.8 msyes

Minesweeper#

The hint on an expert board takes 0.58 s interpreted, 0.23 ms compiled and 5 µs in plain JavaScript; Hazel sweeping a whole intermediate board, 115 moves, takes 122 s interpreted, 35 ms compiled and 4 ms in plain JavaScript.

The program. Three modules (Board, Play, Hint; 212 lines with its vocabulary): the mines laid after the first tap (never in its 3 by 3), each cell’s count, a cell opened (and the empty region around it), flags, a number’s neighbours opened at once, and the 💡 hint: a sure move worked out from the open numbers alone. 🤖 plays the hint’s sure moves one after another.

Randomness. The mines: one number from the page for each cell outside the first tap’s 3 by 3, by Knuth’s selection sampling, so exactly the mines asked for, each place as likely as any other. The hint is deterministic: the same board always gives the same sure move. When no number shows a sure move, the hint says so, and 🤖 guesses a closed cell picked at random by the page, not by Hazel, whose rules have no guessing.

What the work grows with. The board’s size and how much of it is open. The hint reads the board once, row by row, making each open cell with closed neighbours a number to reason from. It makes two passes over those numbers to find the mines they force, checking each number’s closed cells against the mines known so far, a list it walks. Then it looks for a number whose mines are all known. So its work grows with the numbers × their cells × the mines known, and so with the board’s size. Opening an empty cell sweeps the whole board, again and again, until no more cells open.

OperationPositionhazeljshazel-jitno step budgetand plain numbersplain JShazeljs ÷ hazel-jithazel-jit ÷ plain JS
the mines laidbeginner, 9 by 983 ms0.028 ms0.025 ms0.023 ms2.64 µs2,953×11×
a cell openedbeginner, 9 by 97.6 ms7.61 µs7.56 µs7.55 µs0.121 µs1,004×63×
the hint (a sure move)beginner, 9 by 9122 ms0.031 ms0.030 ms0.027 ms4.31 µs3,966×7.1×
the mines laidintermediate, 16 by 16290 ms0.090 ms0.082 ms0.075 ms8.85 µs3,242×10×
a cell openedintermediate, 16 by 1620 ms0.022 ms0.022 ms0.022 ms0.219 µs921×101×
the hint (a sure move)intermediate, 16 by 16363 ms0.133 ms0.130 ms0.118 ms8.66 µs2,740×15×
the mines laidexpert, 16 by 30504 ms0.173 ms0.155 ms0.142 ms0.017 ms2,911×10.0×
a cell openedexpert, 16 by 3039 ms0.046 ms0.040 ms0.041 ms0.336 µs841×137×
the hint (a sure move)expert, 16 by 30583 ms0.227 ms0.237 ms0.161 ms5.11 µs2,568×44×
the page boundary: the game in and outbeginner, 9 by 9—6.90 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
the page boundary: the game in and outintermediate, 16 by 16—0.021 mshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
the page boundary: the game in and outexpert, 16 by 30—0.040 mshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
Whole gameMoveshazeljshazel-jitno step budgetand plain numbersplain JSSame end
Hazel sweeping a board, beginner, 9 by 9152.76 s1.1 ms1.1 ms1.0 ms1.1 msyes
Hazel sweeping a board, intermediate, 16 by 16115121.7 s35 ms36 ms32 ms4.1 msyes
Hazel sweeping a board, expert, 16 by 30252—228 ms222 ms214 ms14 msyes

Go#

Hazel’s choice of move takes 0.59 to 0.91 s interpreted, 0.10 to 0.16 ms compiled, and 8 to 16 µs in plain JavaScript; a whole 9 by 9 game of Hazel against itself, 89 moves, takes 71 s, 17 ms and 5.5 ms. Go gains the most from compiling (5,300×), and plain JavaScript gains 10× more.

The program. One module (Go.hz; 235 lines with its vocabulary): the board as rows of points, a group of stones and its liberties, a move (its captures, no suicide, the ko), a pass, Tromp and Taylor’s area score, and the opponent.

The strategy. Hazel values every empty point as its move, in tenths of a point: what the move takes (20 a stone), saves (15 a stone of its own groups in atari), threatens (6 a stone left in atari) and risks (−12 a stone of a group left with one liberty), its liberties, and where it is (the third line best, the edge worst). It plays the best one, or passes when none is worth more than −3 points, or when the other side has passed and it is ahead.

Randomness. Each point’s worth gets one of the page’s random numbers added before the best is picked, drawn fresh for every move, from 0 up to the most set by the Go page’s randomness slider (2 points by default; 0 to 10). It varies Hazel’s play, breaks ties, and can tip a choice between moves within that many points of each other, or tip a weak move over the −3 point floor where Hazel would have passed. At 0 Hazel plays its best move every time: two games it plays against itself at 0 come out the same, stone for stone.

What the work grows with. The points on the board, for each move. Hazel traces the board’s groups once a turn, then values each of the 81 points (49 on 7 by 7), looking up the groups beside it. A capture is valued by playing it on a copy of the board. In the Hazel, the stone at a point is found by walking the rows to its row, then along that row, so each lookup costs about as many steps as the point is far from the corner. The plain JavaScript reads the stone at a point from an array, in one step. Counting the score floods each empty region.

OperationPositionhazeljshazel-jitno step budgetand plain numbersplain JShazeljs ÷ hazel-jithazel-jit ÷ plain JS
a move played6 moves in17 ms4.49 µs4.15 µs3.83 µs1.47 µs3,885×3.1×
Hazel's choice of move6 moves in588 ms0.105 ms0.093 ms0.077 ms7.63 µs5,611×14×
the score6 moves in755 ms0.138 ms0.110 ms0.105 ms5.69 µs5,452×24×
a move played40 moves in188 ms0.029 ms0.026 ms0.023 ms3.89 µs6,370×7.6×
Hazel's choice of move40 moves in913 ms0.162 ms0.152 ms0.166 ms0.016 ms5,638×10×
the score40 moves in260 ms0.048 ms0.043 ms0.039 ms3.71 µs5,462×13×
the page boundary: the game in and out6 moves in—1.39 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
the page boundary: the game in and out40 moves in—1.40 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
Whole gameMoveshazeljshazel-jitno step budgetand plain numbersplain JSSame end
Hazel against Hazel on 7 by 74217.2 s5.8 ms4.9 ms4.6 ms0.687 msyes
Hazel against Hazel on 9 by 98971.2 s17 ms16 ms15 ms5.5 msyes

Checkers (English draughts)#

Looking 4 moves ahead, Hazel’s move takes 6.2 s interpreted, 2.2 ms compiled and 0.14 ms in plain JavaScript, 2,800× and 16×; the factors hold at every depth, since the three search the same tree, each move further ahead about 3 times as much work.

The program. One module (Checkers.hz; 141 lines with its vocabulary): each side’s pieces as a set of the 32 dark squares kept in a number’s bits, the moves (jumps are compulsory and go on while they can), kings, the end (no move loses, 80 moves with no capture and no man moving draws), and the opponent.

The strategy. Alpha-beta search: Hazel tries each of its moves, then each answer, and so on, as many moves ahead as chosen, valuing the position at the end by material (a man 100, and 2 for each row it has come; a king 160) for the side to move.

Randomness. Ties only. The page passes 48 numbers, one for each move tried at the top. Of the moves with the best value, the one paired with the largest number is played. The search itself is deterministic.

What the work grows with. The search’s depth. With about 8 moves a position, looking one more move ahead costs several times as much, fewer than 8 because alpha-beta cuts off branches that cannot matter. The compiled times grow from 0.046 ms looking 1 ahead to 18.6 ms looking 6 ahead, at the position 8 moves in. Each position’s moves are found from the sets of squares. The Hazel has no bit operations, so it tests a square by dividing the set by a power of two, where the plain JavaScript shifts and masks.

OperationPositionhazeljshazel-jitno step budgetand plain numbersplain JShazeljs ÷ hazel-jithazel-jit ÷ plain JS
the movesthe start37 ms0.012 ms0.012 ms8.89 µs0.572 µs3,049×21×
the moves8 moves in37 ms0.012 ms0.012 ms9.66 µs0.607 µs3,031×20×
the moves30 moves in27 ms9.09 µs9.11 µs7.43 µs0.569 µs2,933×16×
Hazel's move, looking 1 ahead8 moves in130 ms0.046 ms0.049 ms0.039 ms1.75 µs2,815×26×
Hazel's move, looking 1 ahead30 moves in109 ms0.039 ms0.042 ms0.034 ms1.55 µs2,810×25×
Hazel's move, looking 2 ahead8 moves in635 ms0.226 ms0.237 ms0.187 ms0.013 ms2,812×18×
Hazel's move, looking 2 ahead30 moves in498 ms0.180 ms0.187 ms0.152 ms0.010 ms2,759×18×
Hazel's move, looking 3 ahead8 moves in2.12 s0.729 ms0.762 ms0.604 ms0.045 ms2,907×16×
Hazel's move, looking 3 ahead30 moves in1.86 s0.649 ms0.689 ms0.559 ms0.044 ms2,856×15×
Hazel's move, looking 4 ahead8 moves in6.20 s2.2 ms2.2 ms1.7 ms0.139 ms2,856×16×
Hazel's move, looking 4 ahead30 moves in—2.3 ms2.3 ms1.8 ms0.156 ms—15×
Hazel's move, looking 5 ahead8 moves in—6.1 ms6.7 ms5.2 ms0.428 ms—14×
Hazel's move, looking 5 ahead30 moves in—6.9 ms7.2 ms5.9 ms0.407 ms—17×
Hazel's move, looking 6 ahead8 moves in—19 ms20 ms16 ms1.5 ms—12×
Hazel's move, looking 6 ahead30 moves in—20 ms21 ms18 ms1.6 ms—13×
the page boundary: the game in and outthe start—0.141 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
the page boundary: the game in and out8 moves in—0.224 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
the page boundary: the game in and out30 moves in—0.221 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
Whole gameMoveshazeljshazel-jitno step budgetand plain numbersplain JSSame end
Hazel against Hazel, looking 2 ahead (to 60 moves)6024.7 s9.8 ms11 ms9.9 ms0.855 msyes
Hazel against Hazel, looking 4 ahead (a whole game)185—760 ms825 ms697 ms58 msyes
Hazel against Hazel, looking 6 ahead (a whole game)213—5.38 s5.38 s4.54 s385 msyes

Mahjong (Hong Kong rules)#

Mahjong is where plain JavaScript gains least, 4.6 times over compiled: a Hazel player’s turn takes 63 ms interpreted, 23 µs compiled and 2.3 µs in plain JavaScript, and the claims on a discard 60 ms, 21 µs and 9 µs. Eight hands of Hazel playing all four seats take 36 s, 20 ms and 10 ms.

The program. One module (Mahjong.hz; 316 lines with its vocabulary): the deal, a turn (a draw and a discard), the claims on a discard (a chow, a pung, a kong, a win) and which comes first, a winning hand and its faan, the points, and what each Hazel player discards and claims. 🤖 plays your seat by the step’s kind 9, as the Hazel players play theirs.

The strategy. A Hazel player wins when it can, declares a kong when it has one, and otherwise discards the tile that helps its hand least: its other copies, its neighbours in its suit, and a little for the middle of the suit or a scoring honour. On another seat’s discard it claims a win, a kong of three, a pung of a pair that is an honour or has few neighbours, or, as the next seat, a chow that breaks no pair.

Randomness. Only the shuffle: 136 numbers from the page, one a tile as its sort key. The players are deterministic: the same table always gives the same discard and the same claims.

What the work grows with. Whether a hand wins, asked again and again. Every step on another seat’s discard asks, for each of the three other seats, whether that discard would complete its hand. That means trying every way the hand makes a pair and four sets, a recursive search over pungs and chows. A player’s own turn asks it once more, then weighs each kind of tile in its hand.

OperationPositionhazeljshazel-jitno step budgetand plain numbersplain JShazeljs ÷ hazel-jithazel-jit ÷ plain JS
a hand dealtthe first hand180 ms0.042 ms0.039 ms0.039 ms0.021 ms4,255×2.0×
a Hazel player's turn (a step)early in the hand63 ms0.023 ms0.014 ms0.014 ms2.34 µs2,777×9.7×
your optionsyour turn28 ms9.39 µs6.67 µs7.14 µs1.60 µs2,962×5.9×
your turn, played by Hazel (a step)your turn62 ms0.019 ms0.015 ms0.016 ms2.46 µs3,246×7.8×
the claims on a discard (a step)another's discard60 ms0.021 ms0.016 ms0.016 ms8.80 µs2,890×2.4×
the page boundary: the game in and outearly in the hand—2.62 µshazel-jit only: the game from hazeljs's shapes into hazel-jit's and back, which every call through the page's functions pays
Whole gameMoveshazeljshazel-jitno step budgetand plain numbersplain JSSame end
Hazel playing all four seats, one hand1014.62 s5.6 ms4.5 ms5.2 ms2.1 msyes
Hazel playing all four seats, eight hands74635.6 s20 ms22 ms23 ms10 msyes

The same answers, three ways#

The three versions of each game give the same answers, value for value, and in the same order where the order matters: the moves listed, the move chosen, the faan counted. Two Node scripts in hazeljs-examples checked it before anything was timed. node/compare-compiled.mjs plays seeded games and compares every answer of the compiled rules with hazeljs’s, and, with --plain, with the plain JavaScript’s:

Gamehazel-jit against hazeljsplain JS against hazel-jitWhat the plain check covers
Checkers469 answers, 0 differ8,969 answers, 0 differ30 random games: every position’s moves, Hazel’s choice looking 1 and 2 ahead (3 and 4 every tenth move), each move made
Solitaire722 answers, 0 differ48,040 answers, 0 differ40 deals, drawing one and three: every position’s moves, the moves from every place, each move made, the win
Minesweeper571 answers, 0 differ15,137 answers, 0 differ90 boards at the three levels: every hint (all four kinds of answer, 125 of them “take this flag off”), each move it names, random flags kept, chords
Go157 answers, 0 differ5,160 answers, 0 differ20 games of Hazel against itself on 9 by 9: every choice, a random point played (legal or not), each move or pass, the score every tenth turn
Mahjong1,719 answers, 0 differ15,386 answers, 0 differ80 hands: every step and your options, with you discarding at random, making claims, or played by Hazel; every third deal with tied shuffle keys

Then the timing script checked again as it went: each operation’s answer the same all three ways (and both variants), and each whole game ending in the same state. None differed: every operation’s answer was the same all five ways (the three builds and the two variants), and every whole game ended in the same state.

The plain JavaScript keeps the Hazel’s algorithms and its order, not its data structures. Where the Hazel walks a list, the JavaScript indexes an array. Where it divides by a power of two, the JavaScript shifts. Where it looks a value up in a list, the JavaScript uses a Set or a Map. A JavaScript programmer writing the same game would make those choices, and Matthew asked for the JavaScript to be equivalent in the game, its logic and its strategy. Two places keep Hazel’s exact order where a simpler JavaScript would differ. Mahjong’s shuffle sorts the keys with the Hazel’s own merge sort, whose halves are taken alternately and reversed, so tied keys fall the same way. Minesweeper’s hint keeps the order in which the Hazel lists each number’s closed neighbours, because the first sure move found is the one it names.

What next#

  1. Time every hazel-jit change this way. The workflow three-way timing in hazeljs-examples runs on every change to the rules, the compiled programs or the plain JavaScript. Run against each new hazel-jit commit, its results would chart how the distance to plain JavaScript closes, as Matthew put it: “now, and in the future, as the hazel components become better in performance”.
  2. Split the program’s shape from the compiler. A third JavaScript version of one game, written the Hazel’s way (lists of cons cells, division for bits, a tuple for each call), would show how much of the gap to plain JavaScript is Hazel’s vocabulary and how much is hazel-jit’s code. Checkers and Go are the clearest cases.
  3. Calls without a tuple. Every multi-argument call in the compiled code allocates an array for its arguments and reads them back out. Compiling a known function of n arguments to a JavaScript function of n parameters would remove that allocation.
  4. A cheaper page boundary for big values. Minesweeper’s board crosses whole on every call, in and out: 40 µs on an expert board, most of what opening a cell costs. A page could keep hazel-jit’s own value of the game between calls and convert only what it draws, or hazel-jit could take JavaScript arrays as its lists.
  5. The same three ways in a browser, and on a phone. Each page’s ⚙️ Advanced already times its rules, interpreted or compiled. Adding plain JavaScript there would give these numbers on the devices the activities are played on.

How this was put together#

On 2026-11-20, for ^ticket(797). The five games are hazeljs-examples’ own: their rules are the rules/*.hz the pages run, compiled for 0.0.34 (^ticket(794)). The plain JavaScript (<game>/plain.js) was written for this report and is never loaded by the pages.

BuildWhat runs the rulesFrom
1 · hazeljsHazel’s interpreter, as the pages ran their rules until 0.0.34: the game’s rules/*.hz built by Hazel.runProgramhazeljs 0.0.4 from npm
2 · hazel-jitThe same Hazel compiled ahead of time to JavaScript by hazel-jit, wrapped by tools/make-compiled.py with adapters for the page’s values (compiled.js)hazelgrove/hazel trial/794-games-aot: Solitaire 5405a2e87d, Minesweeper 5405a2e87d, Go 5405a2e87d, Checkers d15466c7b1, Mahjong 70d0178872
2a · no step budgetBuild 2 with the step budget’s check taken out of every compiled functionmade from build 2 by node/three-way.mjs, for timing only
2b · and plain numbersBuild 2a with Hazel’s exact-integer + - * / replaced by plain number arithmeticmade from build 2a likewise
3 · plain JSThe same game, rules and strategy written in plain JavaScript (plain.js)hazeljs-examples 40fd48b

The machine. AMD EPYC 9V74 (4 vCPUs), Node 22.23.4, Ubuntu: one GitHub-hosted runner, all five games one after another in one job, so all builds were timed on the same machine: run 44813544646 of the workflow three-way timing, 2026-11-20, 13:41 to 13:51 MST.

The timing. node/three-way.mjs <game> builds the rules with hazeljs as the page does, loads compiled.js and plain.js, and makes the two variants of compiled.js by text replacement. It plays a seeded game to make each operation’s positions (with the compiled rules; all ways answer the same there). Then it times each operation each way: a call too fast for the clock is run in batches of as many calls as take at least a millisecond, and the median batch, per call, is reported. hazeljs is timed at least 3 times and for at least 1.5 s, the others at least 30 times and for at least 0.3 s, after 20 calls to warm up. Whole games are played from the same seed each way: hazeljs once, the others 5 times, keeping the median. Every operation goes through the same functions the page calls, with the page’s values. For hazel-jit that includes converting them in and out (the page boundary, timed by itself on its own rows).

Not timed in a browser. These are Node numbers, on a server processor. Chrome runs the same JavaScript engine as Node (V8); Firefox and Safari have their own, and on a phone every time will be several times longer. The ratios between the three ways are what this report is about.

The data#