plum

#treesitter#compiler#wasm

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

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


441e351 — Peter John 2026-11-11T01:44:44+05:30
docs/benchmarks: simpler-language before and after 2026-11-10 (3cd4692f against 7c82a31f)
docs/benchmarks/2026-11-11-simpler-language-before-after.md ADDED
@@ -0,0 +1,208 @@
1
+ # simpler-language before and after 2026-11-10: compile time, wasm size and run time
2
+
3
+ Taken 2026-11-11 on an Apple M3 Pro (11 cores, 18 GB), macOS 26.6.2. "Before" is simpler-language at `3cd4692f` (2026-11-10 09:27, the morning of 2026-11-10), "after" is its tip at `7c82a31f` (2026-11-11 01:26), 164 commits later. Both compilers were built with `cargo build --release -p plum-cli`, each in its own worktree. Master is not involved.
4
+
5
+ **The machine was loaded.** Other work was running: the load average was 18.8 when the compile timings started, 10 to 15 during the game runs, and fell to about 5 during the scene-tree and test-suite runs. Wall-clock numbers taken under a load above 4 are unreliable, and that includes the in-program times of the games, the micro workloads and the scene trees, since they come from the program's own clock. The before and after runs were alternated, round by round, so both saw the same load, and the ranges are mostly tight. Even so, treat ratios within about 10% as noise. Compile time is given as process CPU time (user plus sys), which the load affects less.
6
+
7
+ ## Short answer
8
+
9
+ - **Compiling got slower.** CPU time is 1.32x for Orb Run (538 ms to 708 ms), 1.40x for Balloon Pop, 1.65x for the scene-tree program, and 1.7x to 2.0x for the small examples (basics: 52 ms to 103 ms). In wall time the gap is smaller (Orb Run's phases add up to 461 ms before and 540 ms after, 1.17x), because the loader now uses several threads, which costs more CPU for less wall time. The same programs now reach about 17 to 25% more std items, and every pass that walks the program got slower by about that much.
10
+ - **The wasm got smaller.** It is 7 to 11% smaller for the games and the scene tree, and 56 to 64% smaller for the small examples. The new post-pass does all of this and more: with `PLUM_NO_WASM_OPT=1` the after wasm is 17 to 19% bigger than before for the games (1.3x to 1.9x for the smaller programs). The web build's `plum.wasm` shrank from 99,308 to 76,817 bytes for Orb Run (0.77x) and from 79,714 to 61,972 for Balloon Pop (0.78x).
11
+ - **The games got faster.** A headless tick of Orb Run went from 5.42 µs to 2.37 µs (0.44x), and Balloon Pop from 1.75 µs to 1.21 µs (0.69x). Both trees print the expected checksums: Orb Run 871028980 and Balloon Pop 234038249 with 3975 pops, on all three builds.
12
+ - **The micro workloads are faster or level, except `map`.** `map` is 3.9x slower (198 ms to 781 ms) because Map is now a persistent tree, not a hash table, so it is a different algorithm. `trig` is 0.56x, but it too is a different algorithm (fdlibm ports, not short series). On the same algorithm, `array` is 0.62x, `str` 0.81x and `particles` 0.84x. `fib`, `loop`, `cons` and `cons_rec` are level.
13
+ - **The scene tree is 4 to 28% faster on every workload.** The biggest gains are on churn (0.72x to 0.75x) and step (0.75x to 0.79x). The checksums agree with before on every cell.
14
+ - **The test suite takes longer**: 6.2 s to 7.6 s wall and 46.6 s to 71.4 s CPU. It also has more tests: 1260 tests in 250 files before, 1380 in 273 after.
15
+ - **`--no-fbip` and `--no-fusion` still change almost nothing**, with one exception: the `cons` pipeline without fusion takes 1005 ms on both trees, against 145 ms with it.
16
+
17
+ ## Method
18
+
19
+ **What "the same program" means.** The two trees don't accept each other's source. Generic syntax moved from `[]` to `<>`, `+` on Str is gone, std files moved (for example `std/Map` became `std/collections/Map`), `Map.set` is gone, and Map became a persistent tree. So each compiler builds its own tree's programs with its own std: `examples/games/orb_run.plum`, `examples/games/kids/balloon_pop.plum`, `examples/functional.plum`, `examples/basics.plum`, `benchmarks/scene_trees/scene_tree.plum` and `benchmarks/master_vs_simpler/branch/*.plum`, each as it stands in its tree. These are the same programs, ported between the two trees: same algorithm, same inputs, same checksums. The exceptions are `map` and `trig`, whose std implementation changed (see below). The micro sources differ only in syntax and import paths, except `map.plum`: its fill loop became a self tail call over `with`, because `set` is gone.
20
+
21
+ **Harness.** A scratch script (not committed) does the following:
22
+
23
+ - It runs each tree's own compiler from that tree's root, so each gets its own std.
24
+ - It times `plum compile` with `getrusage` on the child process (user plus sys CPU, plus wall time), 5 rounds, with the before/after order flipped every round.
25
+ - It writes the game drivers the way each tree's `benchmarks/master_vs_simpler/run.py` does: it imports that file and uses its own `ORB_BRANCH`, `BP_BRANCH`, `strip_main` and `ORB_BRANCH_AGAIN`. The before tree's script requires `--master`, so only its branch side is used.
26
+ - It builds every runtime program with `plum build` (default, `--no-fbip` and `--no-fusion`), then runs every executable once per round, in a rotated order that alternates before and after, for 5 rounds. Each program prints its own time from `io.nowMicros()`.
27
+ - The scene-tree program takes the workload and N as arguments in the after tree. In the before tree it reads them from `scene_trees.args`; the harness writes that file before each before run.
28
+
29
+ Every number is the median of 5, with the range in brackets. The test suite ran once per tree.
30
+
31
+ **Function counts** are read from the wasm's function and import sections.
32
+
33
+ ## Compile time
34
+
35
+ `plum compile`, median of 5. CPU ms is user plus sys. Wall time is under load, so treat it as unreliable.
36
+
37
+ | program | before CPU ms | after CPU ms | after / before | before wall ms | after wall ms |
38
+ |---|---|---|---|---|---|
39
+ | Orb Run | 538 (536-540) | 708 (702-717) | **1.32x** | 540 | 612 |
40
+ | Balloon Pop | 426 (424-426) | 596 (593-600) | **1.40x** | 428 | 503 |
41
+ | functional | 73 (73-74) | 123 (119-126) | **1.69x** | 75 | 93 |
42
+ | basics | 52 (51-52) | 103 (102-109) | **2.00x** | 53 | 69 |
43
+ | scene tree | 248 (247-248) | 408 (401-410) | **1.65x** | 250 | 331 |
44
+
45
+ `PLUM_TIMINGS=1` phase table for Orb Run, median of 5 alternated runs. These are the compiler's own wall-clock times, in ms. A dash means the phase doesn't exist in that tree.
46
+
47
+ | phase | before | after | after / before |
48
+ |---|---|---|---|
49
+ | load | 71.6 | 65.4 | 0.91x |
50
+ | check | 114.7 | 145.5 | 1.27x |
51
+ | dead code (rewrite + re-check) | 34.9 | 41.9 | 1.20x |
52
+ | closure specialisation | 31.6 | 40.0 | 1.27x |
53
+ | fusion (before: includes uniqueness 129.2) | 223.9 | 93.1 | - |
54
+ | in place (uniqueness 103.4) | - | 139.9 | - |
55
+ | fusion + in place | 223.9 | 233.0 | 1.04x |
56
+ | trmc | 25.5 | 33.3 | 1.31x |
57
+ | check + passes | 431.6 | 494.4 | 1.15x |
58
+ | codegen | 25.5 | 31.0 | 1.22x |
59
+ | wasm passes | - | 9.4 | - |
60
+ | compile | 460.9 | 540.2 | **1.17x** |
61
+
62
+ The checker sees 1,516 items (1,080 fns) for Orb Run before and 1,778 (1,301 fns) after, 17% more. After dead code, 870 items remain before and 1,027 after (+18%). For `basics` the counts are 449 against 559 items checked, and 75 against 111 after dead code (+48%). Basics' `check + passes` goes from 23.4 ms to 36.9 ms, and its load phase is level at about 23 ms of wall time.
63
+
64
+ ## Wasm size
65
+
66
+ The wasm bytes are `plum compile`'s output. "fns" counts defined functions; imported ones are in brackets.
67
+
68
+ | program | before bytes | after bytes | after / before | after, `PLUM_NO_WASM_OPT=1` | before fns | after fns | after fns, no post-pass |
69
+ |---|---|---|---|---|---|---|---|
70
+ | Orb Run | 99,308 | 91,885 | 0.93x | 117,882 | 979 (+30) | 735 (+30) | 1,078 |
71
+ | Balloon Pop | 79,714 | 73,476 | 0.92x | 93,364 | 734 (+24) | 559 (+24) | 818 |
72
+ | functional | 12,202 | 5,423 | **0.44x** | 16,496 | 121 (+0) | 37 (+1) | 167 |
73
+ | basics | 4,239 | 1,526 | **0.36x** | 8,056 | 62 (+1) | 10 (+2) | 95 |
74
+ | scene tree | 37,042 | 33,029 | 0.89x | 49,484 | 399 (+11) | 254 (+9) | 461 |
75
+
76
+ `plum build` of a game makes the web folder. The web build's `plum.wasm` is 99,308 bytes before and 76,817 after for Orb Run (0.77x), and 79,714 before and 61,972 after for Balloon Pop (0.78x). The before web wasm is byte for byte the size of `plum compile`'s output. The after web wasm is a further 15 to 16% smaller, because it ships without the name section (`a596fb10`). The rest of the folder is the same size in both trees, including the 51,573-byte `plum_bridge.js`. Building the web folder takes 537 ms against 702 ms of CPU for Orb Run, and 428 against 600 for Balloon Pop.
77
+
78
+ Without the post-pass, the after compiler's wasm is 17 to 19% bigger than before for the games and 1.3x to 1.9x for the scene tree and the small programs. The post-pass (`46ee3ec0` unreachable functions, `07e9bb26` inlining tiny leaves, `c10b729d` redundant casts, `7ff787de` one type per signature) removes 22 to 81% of the bytes. So the size win comes from the post-pass, on top of a program that reaches more std than before.
79
+
80
+ ## Games (headless drivers, update only)
81
+
82
+ Each tree's own driver, spliced by its own `run.py`. Orb Run plays 13 seeds of 3,000 ticks (39,000 ticks), and Balloon Pop 6 seeds of 20,000 ticks (120,000 ticks). Times are the in-program ms, median of 5. "Process CPU" is the whole executable, startup included.
83
+
84
+ | game | build | before ms | after ms | after / before | before µs/tick | after µs/tick | before process CPU ms | after process CPU ms |
85
+ |---|---|---|---|---|---|---|---|---|
86
+ | Orb Run | default | 211 (211-212) | 93 (92-94) | **0.44x** | 5.42 | 2.37 | 429 | 98 |
87
+ | Orb Run | --no-fbip | 210 (210-211) | 93 (92-93) | 0.44x | 5.40 | 2.38 | 432 | 98 |
88
+ | Orb Run | --no-fusion | 211 (210-212) | 94 (93-95) | 0.45x | 5.40 | 2.42 | 434 | 100 |
89
+ | Balloon Pop | default | 210 (209-211) | 145 (145-147) | **0.69x** | 1.75 | 1.21 | 384 | 151 |
90
+ | Balloon Pop | --no-fbip | 208 (207-209) | 147 (145-148) | 0.71x | 1.73 | 1.23 | 386 | 152 |
91
+ | Balloon Pop | --no-fusion | 212 (211-214) | 149 (148-153) | 0.70x | 1.77 | 1.24 | 388 | 155 |
92
+
93
+ The checksums match on every build in both trees. Orb Run prints `checksum 871028980 overs 5 scoreAtOver 80 minesAtEnd 40`, and Balloon Pop `checksum 234038249 pops 3975`.
94
+
95
+ ## Micro workloads
96
+
97
+ `benchmarks/master_vs_simpler/branch/*.plum` from each tree, built with `plum build`. Times are the in-program ms, median of 5. Every build in both trees prints the same checksum.
98
+
99
+ | program | before | after | after / before | before --no-fbip | after --no-fbip | before --no-fusion | after --no-fusion | note |
100
+ |---|---|---|---|---|---|---|---|---|
101
+ | fib | 158 (158-167) | 161 (157-167) | 1.02x | 158 | 158 | 160 | 160 | |
102
+ | loop | 304 (304-308) | 305 (304-322) | 1.00x | 307 | 304 | 304 | 304 | |
103
+ | array | 118 (108-130) | 73 (66-94) | **0.62x** | 117 | 69 | 120 | 70 | reads with `at`, which is now checked |
104
+ | map | 198 (196-255) | 781 (764-790) | **3.94x** | 198 | 770 | 199 | 773 | different algorithm: hash table before, persistent weight-balanced tree after |
105
+ | cons | 143 (142-149) | 145 (140-147) | 1.02x | 146 | 144 | 1,005 | 1,005 | |
106
+ | cons_rec | 1,935 (1,916-3,761) | 1,941 (1,902-2,976) | 1.00x | 1,939 | 1,955 | 1,957 | 1,945 | |
107
+ | str | 766 (758-797) | 617 (611-644) | **0.81x** | 765 | 614 | 760 | 614 | |
108
+ | particles | 213 (212-215) | 179 (179-179) | **0.84x** | 215 | 179 | 214 | 179 | |
109
+ | trig | 88 (88-106) | 49 (49-72) | 0.56x | 88 | 49 | 88 | 49 | different algorithm: short series before, fdlibm ports after |
110
+
111
+ ## Scene tree
112
+
113
+ Each tree's `benchmarks/scene_trees/scene_tree.plum`, default build only. Times are the in-program ms, median of 5. The before program times itself with the whole-ms clock and the after one with the microsecond clock, so the N = 1000 cells are coarse. Every cell's checksum is the same in both trees.
114
+
115
+ | workload | N | before | after | after / before |
116
+ |---|---|---|---|---|
117
+ | step | 1000 | 23 (23-23) | 18 (18-18) | 0.79x |
118
+ | step | 10000 | 203 (201-237) | 153 (152-154) | **0.75x** |
119
+ | churn | 1000 | 43 (42-43) | 32 (31-45) | 0.74x |
120
+ | churn | 10000 | 389 (388-415) | 281 (280-282) | **0.72x** |
121
+ | draw | 1000 | 32 (31-32) | 27 (27-28) | 0.85x |
122
+ | draw | 10000 | 295 (295-296) | 257 (255-277) | 0.87x |
123
+ | hit | 1000 | 23 (23-24) | 19 (19-19) | 0.83x |
124
+ | hit | 10000 | 200 (199-218) | 186 (185-187) | 0.93x |
125
+ | step, no transforms | 1000 | 18 (18-18) | 15 (15-16) | 0.85x |
126
+ | step, no transforms | 10000 | 159 (157-160) | 137 (135-144) | 0.86x |
127
+ | step, eager transforms | 1000 | 48 (48-49) | 43 (42-43) | 0.89x |
128
+ | step, eager transforms | 10000 | 460 (459-481) | 424 (420-456) | 0.92x |
129
+ | churn, apply after | 1000 | 47 (47-65) | 35 (34-35) | 0.75x |
130
+ | churn, apply after | 10000 | 430 (429-431) | 323 (322-341) | 0.75x |
131
+ | step, 60 kept | 1000 | 28 (27-28) | 23 (22-23) | 0.81x |
132
+ | step, 60 kept | 10000 | 1,769 (1,747-1,786) | 1,694 (1,651-1,721) | 0.96x |
133
+ | churn, 60 kept | 1000 | 47 (47-48) | 37 (36-37) | 0.78x |
134
+ | churn, 60 kept | 10000 | 1,955 (1,928-1,999) | 1,866 (1,850-1,882) | 0.95x |
135
+ | mostly still | 1000 | 16 (16-16) | 13 (13-14) | 0.84x |
136
+ | mostly still | 10000 | 141 (141-155) | 117 (117-130) | 0.83x |
137
+ | mostly still, one group | 1000 | 16 (16-17) | 13 (13-13) | 0.84x |
138
+ | mostly still, one group | 10000 | 141 (139-162) | 116 (116-116) | 0.82x |
139
+
140
+ ## Test suite
141
+
142
+ `target/release/plum test std examples tests`, once per tree. Each tree runs its own tests, and every test passed in both.
143
+
144
+ | | before | after | after / before |
145
+ |---|---|---|---|
146
+ | wall s | 6.2 | 7.6 | 1.23x |
147
+ | CPU s (user + sys, all workers) | 46.6 | 71.4 | **1.53x** |
148
+ | tests (files) | 1,260 (250) | 1,380 (273) | 1.10x (1.09x) |
149
+ | CPU ms per test | 37 | 52 | 1.40x |
150
+
151
+ ## What stands out
152
+
153
+ Measured:
154
+
155
+ 1. **Compile time is the one broad regression.** It is 1.3x to 2x the CPU time on every program measured, and the test suite's CPU per test is 1.4x. The phase table puts it in the passes that walk the whole program: check (1.27x), dead code (1.20x), closure specialisation (1.27x), trmc (1.31x) and codegen (1.22x). Each of these grows by about as much as the item count grows (+17% for Orb Run). Moving the in-place updates out of fusion into their own pass (`4adfed87`, `2f516826`) didn't make that work cheaper: fusion plus in place is 233 ms against 224 ms, and the new pass brings one more re-check (28 ms). The wasm post-pass costs 9 ms. The small programs regressed most: basics reaches 48% more items after dead code than before.
156
+ 2. **Load got faster in wall time (72 ms to 65 ms) but probably costs more CPU.** `00217f59` parses the imports on several threads, which is consistent with the CPU ratio (1.32x) being well above the wall ratio (1.17x) for Orb Run. CPU time per phase wasn't measured, so this is an inference.
157
+ 3. **The games tick 1.4x to 2.3x faster, with no change from `--no-fbip` or `--no-fusion`.** The executables also start much more cheaply. Before, Orb Run's process used 429 ms of CPU for 211 ms of work. After, it uses 98 ms for 93 ms. That is consistent with `d3dabfb0` (a precompiled module in `plum build` executables), but startup wasn't timed on its own.
158
+ 4. **The persistent Map costs 3.9x the hash table** on 200,000 inserts and lookups: about 780 ns per insert plus lookup, against about 200 ns. `--no-fbip` doesn't change it, so the tree's insert isn't reusing cells now either.
159
+ 5. **Checked `Slice.at` (`2c8333e2`, `0faae622`) didn't make `array` slower.** It got faster (0.62x, though its before range is wide, 108 to 130 ms), most likely from inlining tiny leaves (`07e9bb26`).
160
+ 6. **Hand-written recursion with closure arguments didn't change.** `cons_rec` takes 1.94 s, against 145 ms for the same pipeline through the std with fusion, and 1005 ms through the std without fusion. `fib` and `loop` are level too.
161
+ 7. **On the scene tree, "60 kept" at N = 10000 is 11x plain step** (1694 ms against 153 ms), while at N = 1000 it is only 1.3x. It also gained least from the two days (0.95x to 0.96x).
162
+
163
+ Guesses, not measured:
164
+
165
+ - The extra std items come from the larger std (Decimal formatting and parsing, fdlibm math, Map's longer API, `compare` and `eq` everywhere), reached through interpolation and `toStr`. Which items `basics` now pulls in wasn't checked.
166
+ - The game speed-up most likely comes from `8461d00e` (pointer routing finds the hit first, cheaper idle ticks), the codegen inlining and cast removal (`07e9bb26`, `c10b729d`), and `4c05ed80` (in-place updates on generic types). The hover change (`3955e744`, `ctx.pointedAt` found once per step) adds a hit test to every step, but its cost is hidden inside the net gain and wasn't isolated.
167
+ - The "60 kept" gap at N = 10000 looks like garbage collector pressure from live snapshots rather than tree work, since the same tree without snapshots costs 153 ms.
168
+
169
+ ## Where performance work would pay off next
170
+
171
+ Ranked by what these numbers show:
172
+
173
+ 1. **Compile time** (not on the candidate list, but the largest regression measured). Every whole-program pass grew with the item count, and small programs now reach many more std items. Ways to win it back: prune the std before checking, check each std item once and reuse it across programs and tests, and do fewer re-checks (there are 5 per compile, 25 to 29 ms each for Orb Run). The test suite would gain the most, at 52 ms of CPU per test.
174
+ 2. **Map insert: cell reuse for generic methods, and a native `Int.compare`.** This is the largest runtime regression (3.9x on `map`), and `--no-fbip` shows that no reuse happens now. The scene tree's churn folds a Map too, so it should benefit, but we have no number for that share.
175
+ 3. **Typed closure calls.** `cons_rec` (1.94 s) and `cons` without fusion (1.0 s) are both closure-heavy and didn't move in two days, while fusion, which removes the closure calls, makes the same work 7 to 13x faster. This is indirect evidence; no profile was taken.
176
+ 4. **The scene tree's structure with kept snapshots.** "60 kept" at N = 10000 costs 11 times a plain step. Sharing more structure between snapshots, or allocating less per step, would show up there. Plain step, draw and hit are already improving.
177
+
178
+ No evidence either way from these runs:
179
+
180
+ - unboxed enum payloads
181
+ - allocation-free Option and `for` loops
182
+ - statics slower than free functions (none of these programs separates the two)
183
+
184
+ Unchecked reads in `for` over a Slice also have no evidence for them: checked `at` showed no cost in `array`, which got faster. The games' remaining 1.2 to 2.4 µs per tick wasn't profiled, so it doesn't point to any one item.
185
+
186
+ ## Caveats
187
+
188
+ - The load was 5 to 19 during the runs. The in-program times are wall clock and were affected; the alternation and the tight ranges limit the damage, but small ratios (within about 10%) are not meaningful.
189
+ - `map` and `trig` compare different algorithms in the two trees, and `map.plum` changed shape (a `for` loop over `set` became a tail call over `with`).
190
+ - The before scene-tree program times itself in whole ms.
191
+ - Each tree's test suite is a different set of tests.
192
+ - The phase table's times are the compiler's own wall-clock times. CPU per phase wasn't measured.
193
+ - Function counts stop at the first non-function import, which is fine for these modules: their function imports come first.
194
+
195
+ ## How to rerun
196
+
197
+ After (any simpler-language checkout at or after `7c82a31f`):
198
+
199
+ ```sh
200
+ cargo build --release -p plum-cli
201
+ python3 benchmarks/master_vs_simpler/run.py # micro and games, 3 builds, 5 rounds
202
+ python3 benchmarks/scene_trees/run.py --plum target/release/plum --sizes 1000,10000
203
+ PLUM_TIMINGS=1 target/release/plum compile examples/games/orb_run.plum -o /tmp/orb.wasm
204
+ PLUM_NO_WASM_OPT=1 target/release/plum compile examples/games/orb_run.plum -o /tmp/orb.wasm
205
+ target/release/plum test std examples tests
206
+ ```
207
+
208
+ Before (`git worktree add --detach <dir> 3cd4692f`, then `cargo build --release -p plum-cli` there): both `run.py` scripts in that tree require `--master`. For the games, take the driver text from that tree's `run.py` (`ORB_BRANCH`, `BP_BRANCH`, `strip_main`, `ORB_BRANCH_AGAIN`), splice it as `write_games` does, and build with that tree's compiler from its root. Its micro programs build as they are. Its scene-tree program reads `<workload> <N>` from `scene_trees.args` in the working folder. Alternate the before and after runs. Both trees must print the checksums above. All measurements here took about 7 minutes after the builds.