plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


f683479 — Peter John 2026-11-11T08:08:51+05:30
docs/benchmarks: master e63393fb against simpler-language 5d384800
docs/benchmarks/2026-11-11-master-vs-simpler-language.md ADDED
@@ -0,0 +1,166 @@
1
+ # master against simpler-language, again: compile time, wasm size and run time
2
+
3
+ Taken 2026-11-11 on an Apple M3 Pro (18 GB), macOS 26.6.2. Master at `e63393fb` (a detached worktree, 25 commits after the `cd59829` of [2026-11-09](2026-11-09-master-vs-simpler-language.md)), simpler-language at `5d384800` plus the driver fixes of `234406e9` (see [Method](#method)). Both compilers built with `cargo build --release -p plum-cli`. Every run time is the median of 5 fresh processes, with the range in brackets, in ms. The runs went one benchmark at a time, after the [before and after rerun](2026-11-11-simpler-language-before-after.md), each started once the 1-minute load average was at or below 3. The load was 2.5 at the start of the micro and game runs (4.1 at their end), 4.1 to 4.6 during the scene trees (another session was running a Rust test binary), and 2.4 during the compile timings. The machine was short of free memory during the scene trees (1.8 GB of swap in use).
4
+
5
+ "branch" below means simpler-language.
6
+
7
+ ## Short answer
8
+
9
+ - **Same source on both: none**, as on 2026-11-09. Every number is from a port or a driver written per branch. Every port that still runs prints the same checksum on both, and so do both games: Orb Run 871028980 and Balloon Pop 234038249 with 3975 pops.
10
+ - **Two ports and two of master's three scene trees no longer exist on master.** `cons` and `cons_rec` use master's `LinkedList`, and master's `game_tree.plum` and `std/game_enum_tree` are gone: master removed all three in `ed6fec37`. Those rows have no master number.
11
+ - **Compiling a game now takes about as long on both.** The branch takes 1.06x master's CPU time for the Orb Run driver (626 ms against 591 ms) and 1.08x for Balloon Pop, and 0.90x and 0.90x its wall time. On 2026-11-09 it took 5 times the wall time. On small programs the branch is now faster: 0.72x to 0.90x the CPU, 0.45x to 0.63x the wall.
12
+ - **The branch's wasm is now smaller**: 0.69x master's for the Orb Run driver and 0.56x for Balloon Pop, against 2.05x and 2.08x on 2026-11-09. Small programs are 0.14x to 0.24x master's size.
13
+ - **Orb Run now ticks faster on the branch, Balloon Pop still slower.** Orb Run: 2.31 µs a tick against master's 2.72 µs (0.85x, was 1.42x). Balloon Pop: 1.18 µs against 0.40 µs (2.94x, was 3.13x). Both branches got much faster since 2026-11-09, master by 4x on Orb Run and 3x on Balloon Pop.
14
+ - **The scene tree is mixed against master's `std/game`.** The branch is faster on step, step without transforms, draw and N = 1000 hit (0.71x to 0.96x), level on hit at N = 10000, and slower on churn (1.13x to 1.38x), churn with the apply walk (1.27x to 1.53x) and eager transforms (1.47x to 1.67x). On 2026-11-09 it beat `std/game` on churn, draw and hit; master's tree got 3 to 5.5 times faster on those since.
15
+ - **Micro workloads:** the branch is faster on `array` (0.56x) and `str` (0.86x), level on `loop` and `trig`, and slower on `fib` (1.09x), `map` (1.63x, a persistent tree against master's hash table) and `particles` (1.43x).
16
+
17
+ ## Method
18
+
19
+ As on [2026-11-09](2026-11-09-master-vs-simpler-language.md#method): the micro workloads are the ports in `benchmarks/master_vs_simpler/{master,branch}/`, the games are headless drivers that `benchmarks/master_vs_simpler/run.py` writes around each branch's own game, and the scene trees run through `benchmarks/scene_trees/run.py`. Each compiler compiles with its own std.
20
+
21
+ ```sh
22
+ python3 benchmarks/master_vs_simpler/run.py --master <master> --only fib,loop,array,map,str,particles,trig,orb_run,balloon_pop
23
+ python3 benchmarks/scene_trees/run.py --master <master> --master-plum <master>/target/release/plum \
24
+ --plum target/release/plum --sizes 1000,10000
25
+ ```
26
+
27
+ **What had to change for master `e63393fb`** (commit `234406e9`, nothing else):
28
+
29
+ - Master's games were moved to the trait-based `std/game` (`d5891a23`, `43d29d77`, `e63393fb`). Their `main` now returns `Game`, and `OrbitRunner` and `BalloonPop` no longer have an `update`; they hold the `Game` in a `game` field. The driver now strips `fun main(io: Io) -> Game` and calls `g.game.update(io, input, 1.0 / 60.0)` where it called `g.update(...)`. `OrbitRunner.headless`, `BalloonPop.headless`, `g.world.run`, `g.world.mineList`, `g.field.run` and `Input.sized` are unchanged. The checksums show both drivers still play the same games as the branch's.
30
+ - Master removed `std/collections/LinkedList` (`ed6fec37`). Six ports (`array`, `fib`, `loop`, `map`, `str`, `trig`) imported it without using it: the import line was dropped. `cons` and `cons_rec` build on `LinkedList` and no longer compile on master; they weren't rewritten, and the run leaves them out with `--only`.
31
+ - The same commit removed `benchmarks/scene_trees/game_tree.plum` and `std/game_enum_tree` from master, so `game_tree` and `benchmarks/scene_trees/master/game_enum_tree_kept.plum` no longer build there. `scene_trees/run.py` now leaves out a master program that doesn't build, says so, and gives the ratio against the first master program that built. Only master's `std/game` tree (`benchmarks/scene_trees/game.plum`) runs. It is now the trait-based tree, different code from 2026-11-09's, with the same checksums.
32
+
33
+ **Compile time and wasm size** come from a scratch script, not from `run.py`'s wall-clock column: it times `plum compile` of the same sources (the micro ports, the two drivers that `run.py` wrote, and the scene-tree programs) with `wait4` on the child, user plus sys CPU and wall, 5 rounds, alternating master and the branch. `run.py`'s own compile column agreed with it within a few percent, except its first program, which was slower on its first round.
34
+
35
+ ## Micro workloads (ports, same checksums)
36
+
37
+ | program | master | branch | branch --no-fbip | branch --no-fusion | branch / master | 2026-11-09 |
38
+ |---|---|---|---|---|---|---|
39
+ | fib | 138 (138-148) | 151 (150-158) | 152 (150-173) | 151 (150-173) | **1.09x** | 1.12x |
40
+ | loop | 322 (308-409) | 320 (310-341) | 329 (309-380) | 321 (310-370) | 0.99x | 1.00x |
41
+ | array | 112 (112-112) | 63 (63-63) | 63 (63-64) | 63 (63-63) | **0.56x** | 0.96x |
42
+ | map | 177 (176-178) | 288 (285-291) | 476 (469-481) | 485 (478-490) | **1.63x** | 0.95x |
43
+ | cons | - | 138 | 138 | 964 | - | 0.04x |
44
+ | cons_rec | - | 1,852 | 1,835 | 1,826 | - | 0.99x |
45
+ | str | 699 (696-702) | 599 (595-603) | 602 (595-608) | 602 (597-606) | **0.86x** | 0.99x |
46
+ | particles | 123 (122-124) | 175 (175-176) | 175 (175-176) | 175 (175-176) | **1.43x** | 1.24x |
47
+ | trig | 48 (47-55) | 48 (47-48) | 48 (47-51) | 48 (47-60) | 1.00x | 1.17x |
48
+
49
+ The `cons` and `cons_rec` branch numbers are from the [before and after rerun](2026-11-11-simpler-language-before-after.md#micro-workloads), taken half an hour earlier. `loop` has wide ranges on both sides here (it took 298 ms with tight ranges in that rerun); read it as level. The branch's `map` is a persistent weight-balanced tree, and master's a hash table, so it compares two algorithms.
50
+
51
+ ## Scene trees (different code, same scene, same checksums)
52
+
53
+ Master's `std/game` (`benchmarks/scene_trees/game.plum`, master's compiler and std) against the branch's `benchmarks/scene_trees/scene_tree.plum`. Both time themselves with `io.nowMicros()`. Every cell's checksum agreed across all four versions on every run. The load was 4.1 to 4.6, and some ranges are wide; the medians agree with the before and after rerun's branch numbers within 3%.
54
+
55
+ | workload | N | master std/game | branch | branch --no-fbip | branch --no-fusion | branch / std/game | 2026-11-09 |
56
+ |---|---|---|---|---|---|---|---|
57
+ | step | 1000 | 18 (18-18) | 17 (17-18) | 17 (17-18) | 17 (17-21) | 0.96x | 1.29x |
58
+ | step | 10000 | 187 (182-200) | 149 (147-166) | 149 (148-167) | 148 (147-160) | **0.80x** | 1.17x |
59
+ | churn | 1000 | 22 (22-22) | 30 (30-30) | 30 (30-30) | 30 (30-30) | **1.38x** | 1.60x |
60
+ | churn | 10000 | 240 (239-245) | 272 (271-274) | 273 (272-315) | 273 (271-378) | **1.13x** | 0.46x |
61
+ | draw | 1000 | 35 (35-39) | 27 (26-33) | 27 (27-49) | 27 (27-28) | 0.77x | 0.50x |
62
+ | draw | 10000 | 346 (344-368) | 251 (248-403) | 251 (245-272) | 252 (251-495) | **0.72x** | 0.51x |
63
+ | hit | 1000 | 24 (23-31) | 19 (19-23) | 19 (19-22) | 20 (19-24) | 0.78x | 0.48x |
64
+ | hit | 10000 | 185 (180-200) | 182 (181-194) | 181 (177-191) | 188 (184-196) | 0.98x | 0.48x |
65
+ | step, no transforms | 1000 | 18 (18-18) | 15 (15-21) | 15 (15-18) | 15 (15-19) | 0.84x | 1.00x |
66
+ | step, no transforms | 10000 | 187 (184-263) | 132 (128-155) | 132 (131-150) | 133 (132-139) | **0.71x** | 0.92x |
67
+ | step, eager transforms | 1000 | 25 (25-30) | 42 (41-47) | 41 (41-49) | 42 (42-62) | **1.67x** | 1.02x |
68
+ | step, eager transforms | 10000 | 281 (280-465) | 413 (395-681) | 415 (396-912) | 415 (406-769) | **1.47x** | 1.02x |
69
+ | churn, apply after | 1000 | 22 (22-33) | 34 (34-40) | 34 (34-63) | 34 (33-50) | **1.53x** | 1.80x |
70
+ | churn, apply after | 10000 | 246 (238-455) | 314 (312-642) | 314 (312-518) | 315 (312-476) | **1.27x** | 0.51x |
71
+
72
+ The branch alone, for the workloads master never had (master's mutable tree can't keep snapshots, and has no still leaves): step with 60 kept 22 ms at N = 1000 and 1,641 ms at 10000, churn with 60 kept 35 and 1,784 ms, mostly still 13 and 112 ms, mostly still in one group 13 and 110 ms. With `game_enum_tree` gone, there is no master number to set the 60-kept rows against.
73
+
74
+ ## Games (headless, ported drivers)
75
+
76
+ | game | ticks | master | branch | branch --no-fbip | branch --no-fusion | branch / master | per tick, master / branch | 2026-11-09 |
77
+ |---|---|---|---|---|---|---|---|---|
78
+ | Orb Run | 13 seeds × 3000 | 106 (103-106) | 90 (89-93) | 89 (89-91) | 90 (90-90) | **0.85x** | 2.72 / 2.31 µs | 1.42x (10.9 / 15.5 µs) |
79
+ | Balloon Pop | 6 seeds × 20000 | 48 (48-49) | 142 (141-143) | 141 (140-143) | 143 (143-145) | **2.94x** | 0.40 / 1.18 µs | 3.13x (1.26 / 3.93 µs) |
80
+
81
+ Both print the 2026-11-09 checksums on master and on all three branch builds: Orb Run `checksum 871028980 overs 5 scoreAtOver 80 minesAtEnd 40`, Balloon Pop `checksum 234038249 pops 3975`. The branch's Orb Run still plays with master's restart rule (`ORB_BRANCH_AGAIN`).
82
+
83
+ ## Compile time and wasm size
84
+
85
+ `plum compile`, median of 5. CPU ms is user plus sys; wall ms is the median wall time. "fns" counts defined functions, imported ones in brackets.
86
+
87
+ | program | master CPU ms | branch CPU ms | ratio | master wall ms | branch wall ms | ratio | master wasm bytes | branch wasm bytes | ratio | master fns | branch fns |
88
+ |---|---|---|---|---|---|---|---|---|---|---|---|
89
+ | fib | 197 (196-198) | 144 (143-148) | 0.73x | 199 | 90 | 0.45x | 34,516 | 4,697 | 0.14x | 319 (+22) | 45 (+3) |
90
+ | loop | 197 (196-197) | 144 (142-146) | 0.73x | 198 | 90 | 0.45x | 34,548 | 4,731 | 0.14x | 319 (+22) | 45 (+3) |
91
+ | array | 197 (197-198) | 147 (145-148) | 0.74x | 199 | 93 | 0.47x | 34,669 | 5,538 | 0.16x | 319 (+22) | 54 (+3) |
92
+ | map | 199 (198-200) | 178 (177-180) | 0.90x | 201 | 127 | 0.63x | 36,583 | 6,596 | 0.18x | 334 (+22) | 56 (+3) |
93
+ | str | 196 (195-197) | 142 (139-145) | 0.72x | 198 | 91 | 0.46x | 34,553 | 4,765 | 0.14x | 318 (+22) | 45 (+3) |
94
+ | particles | 181 (181-182) | 152 (150-155) | 0.84x | 183 | 101 | 0.55x | 35,242 | 6,387 | 0.18x | 325 (+22) | 61 (+3) |
95
+ | trig | 197 (197-198) | 152 (150-153) | 0.77x | 199 | 98 | 0.49x | 34,547 | 8,304 | 0.24x | 318 (+22) | 61 (+3) |
96
+ | Orb Run driver | 591 (589-592) | 626 (620-628) | **1.06x** | 592 | 530 | 0.90x | 105,755 | 73,477 | **0.69x** | 999 (+58) | 550 (+18) |
97
+ | Balloon Pop driver | 508 (506-530) | 548 (546-551) | **1.08x** | 510 | 458 | 0.90x | 92,476 | 51,597 | **0.56x** | 858 (+58) | 378 (+14) |
98
+ | scene tree | 402 (401-402) | 407 (405-411) | 1.01x | 404 | 329 | 0.81x | 70,003 | 33,089 | 0.47x | 687 (+49) | 247 (+9) |
99
+
100
+ Master's compiler is single-threaded: its CPU and wall times are the same. The branch's loader parses on several threads, so its CPU is above its wall. With `PLUM_THREADS=1` the branch's CPU for the Orb Run game is about 66 ms lower ([before and after rerun](2026-11-11-simpler-language-before-after.md#compile-time)); that wasn't measured for the drivers.
101
+
102
+ ## Against 2026-11-09
103
+
104
+ Branch / master ratios, then and now. The 2026-11-09 compile times were wall time; both columns of wall are given.
105
+
106
+ | measure | 2026-11-09 | 2026-11-11 | what moved |
107
+ |---|---|---|---|
108
+ | compile, Orb Run driver | 4.99x (wall) | 0.90x wall, 1.06x CPU | branch 3,259 to 530 ms wall; master 654 to 592 |
109
+ | compile, Balloon Pop driver | 5.01x (wall) | 0.90x wall, 1.08x CPU | branch 2,381 to 458; master 475 to 510 |
110
+ | compile, micro ports | 1.03x to 1.40x (wall) | 0.45x to 0.63x wall, 0.72x to 0.90x CPU | branch about 200 to about 90 ms; master about 180 to about 197 |
111
+ | compile, scene tree | 4.2x against std/game (wall) | 0.81x wall, 1.01x CPU | branch 1,409 to 329; master 333 to 404 |
112
+ | wasm, Orb Run driver | 2.05x | 0.69x | branch 178,376 to 73,477 bytes; master 87,205 to 105,755 |
113
+ | wasm, Balloon Pop driver | 2.08x | 0.56x | branch 152,027 to 51,597; master 73,087 to 92,476 |
114
+ | wasm, micro ports | 1.02x to 1.29x | 0.14x to 0.24x | branch about 28 KB to 5 to 8 KB; master about 23 KB to about 35 KB |
115
+ | wasm, scene tree | 1.7x against std/game | 0.47x | branch 85,255 to 33,089; master 49,066 to 70,003 |
116
+ | Orb Run tick | 1.42x | 0.85x | branch 15.5 to 2.31 µs; master 10.9 to 2.72 µs |
117
+ | Balloon Pop tick | 3.13x | 2.94x | branch 3.93 to 1.18 µs; master 1.26 to 0.40 µs |
118
+ | scene tree step, N = 10000 | 1.17x | 0.80x | branch 196 to 149 ms; master 167 to 187 |
119
+ | scene tree churn, N = 10000 | 0.46x | 1.13x | branch 376 to 272; master 821 to 240 |
120
+ | scene tree draw, N = 10000 | 0.51x | 0.72x | branch 744 to 251; master 1,472 to 346 |
121
+ | scene tree hit, N = 10000 | 0.48x | 0.98x | branch 486 to 182; master 1,010 to 185 |
122
+ | scene tree eager transforms, N = 10000 | 1.02x | 1.47x | branch 1,256 to 413; master 1,235 to 281 |
123
+ | fib | 1.12x | 1.09x | level on both |
124
+ | array | 0.96x | 0.56x | branch 105 to 63 ms; master 110 to 112 |
125
+ | map | 0.95x | 1.63x | branch 165 to 288 (hash table to persistent tree); master 173 to 177 |
126
+ | str | 0.99x | 0.86x | branch 727 to 599; master 737 to 699 |
127
+ | particles | 1.24x | 1.43x | branch 207 to 175; master 166 to 123 |
128
+ | trig | 1.17x | 1.00x | branch 226 to 48 (fdlibm); master 194 to 48 (`47e45c40` fdlibm, `8c207cdc` native float ops) |
129
+ | cons | 0.04x | - | master's `LinkedList` is gone |
130
+
131
+ ## What stands out
132
+
133
+ Measured:
134
+
135
+ 1. **The compile-time and size gaps of 2026-11-09 are gone.** The branch's game compile went from 5x master's wall time to 0.9x, and its wasm from 2x master's to 0.56x to 0.69x. In CPU the branch is still 6 to 8% above master on the games, because of its loader's threads. On small programs it is 10 to 28% under master's CPU: master now compiles about 35 KB of std into every program, the branch 5 to 8 KB.
136
+ 2. **Master's games got 3 to 4 times faster too**, so the game ratios moved less than either side did. Orb Run turned around (1.42x to 0.85x). Balloon Pop's tick is still about 3 times master's (1.18 µs against 0.40 µs). On 2026-11-09 that gap pointed to a fixed cost per tick in the branch's `Game.step`; master has cut its own fixed cost by about as much as the branch has, so that reading still holds, still without a profile.
137
+ 3. **Master's new `std/game` tree is 3 to 5.5 times faster than its old one on churn, draw, hit and eager transforms**, and the branch's tree now loses on churn (1.13x to 1.38x), the apply walk (1.27x to 1.53x) and eager transforms (1.47x to 1.67x). It still wins on step (0.80x at N = 10000), step without transforms (0.71x) and draw (0.72x).
138
+ 4. **`particles` is the one micro workload where the gap grew** (1.24x to 1.43x): master got 26% faster, the branch 15%. `map` turned from 0.95x to 1.63x because the branch's Map is now a persistent tree.
139
+ 5. **`--no-fbip` and `--no-fusion` change only `map`** (288 to 476 and 485 ms) among these programs, plus `cons` from the rerun. Master has neither flag.
140
+
141
+ Guesses, not measured:
142
+
143
+ - Master's game speed-up most likely comes from the trait-based `std/game` (`4c0e7178`, `67c83a12`, `d5891a23`, `43d29d77`) and `1efbb733` (no `ref.cast` on field reads and writes of self); the commits weren't measured apart.
144
+ - Master's bigger wasm for small programs is most likely the std it now reaches from `main` (Decimal, fdlibm math, Json, traits; `8eff5b3c`, `47e45c40`, `44e6d58a`); which items it pulls in wasn't checked.
145
+
146
+ ## Caveats
147
+
148
+ - Every comparison is between ports or per-branch drivers. Two ports and two of master's scene trees have no master side any more.
149
+ - The scene-tree runs had a load of 4.1 to 4.6 and little free memory, and some ranges are wide.
150
+ - Only update ticks are timed for the games.
151
+ - Master's game code and its `std/game` are different code from 2026-11-09's. The checksums say they do the same work.
152
+ - The 2026-11-09 compile times are wall time on single-threaded compilers; the branch is no longer single-threaded, so the CPU column is the fairer comparison now.
153
+
154
+ ## How to rerun
155
+
156
+ From a simpler-language checkout at or after `234406e9`, with master's compiler built in a separate checkout:
157
+
158
+ ```sh
159
+ cargo build --release -p plum-cli
160
+ git worktree add --detach <master> master && (cd <master> && cargo build --release -p plum-cli)
161
+ python3 benchmarks/master_vs_simpler/run.py --master <master> --only fib,loop,array,map,str,particles,trig,orb_run,balloon_pop
162
+ python3 benchmarks/scene_trees/run.py --master <master> --master-plum <master>/target/release/plum \
163
+ --plum target/release/plum --sizes 1000,10000
164
+ ```
165
+
166
+ The micro ports and games took about 2 minutes, the scene trees about 2 minutes, and the compile timings about a minute.