wardite 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +191 -0
  3. data/Makefile +14 -0
  4. data/README.md +80 -1
  5. data/Rakefile +5 -0
  6. data/benchmark/README.md +500 -0
  7. data/benchmark/build_call_profile.rb +42 -0
  8. data/benchmark/call_cost_worker.rb +27 -0
  9. data/benchmark/compare.rb +93 -0
  10. data/benchmark/compare_call_types.rb +212 -0
  11. data/benchmark/compare_dispatch.rb +123 -0
  12. data/benchmark/compare_engines.rb +119 -0
  13. data/benchmark/compare_optimizations.rb +139 -0
  14. data/benchmark/engine_phases.rb +30 -0
  15. data/benchmark/figures/README.md +35 -0
  16. data/benchmark/figures/plot_spinel_comparison.py +137 -0
  17. data/benchmark/figures/spinel_new_vm_candlestick.png +0 -0
  18. data/benchmark/figures/spinel_new_vm_candlestick.svg +7615 -0
  19. data/benchmark/figures/spinel_new_vm_summary.csv +9 -0
  20. data/benchmark/figures/spinel_new_vm_summary.json +82 -0
  21. data/benchmark/float_m5.wat +42 -0
  22. data/benchmark/i32_call_arities.wat +89 -0
  23. data/benchmark/i32_calls.wat +174 -0
  24. data/benchmark/i32_memory.wat +58 -0
  25. data/benchmark/i32_mix.wat +80 -0
  26. data/benchmark/i64_m4.wat +55 -0
  27. data/benchmark/investigate_calls.rb +231 -0
  28. data/benchmark/investigate_generated_guards.rb +218 -0
  29. data/benchmark/m3_call_worker.rb +38 -0
  30. data/benchmark/measure_m1.rb +51 -0
  31. data/benchmark/measure_m2.rb +55 -0
  32. data/benchmark/measure_m3_calls.rb +89 -0
  33. data/benchmark/measure_m4.rb +134 -0
  34. data/benchmark/measure_m5_boundary.rb +41 -0
  35. data/benchmark/measure_wasi_write.rb +75 -0
  36. data/benchmark/optimization_worker.rb +23 -0
  37. data/benchmark/results/call_arities_exploratory_2026-11-04.json +4320 -0
  38. data/benchmark/results/call_arities_spinel_2026-11-04.json +1200 -0
  39. data/benchmark/results/call_cost_spinel_2026-11-04.json +2392 -0
  40. data/benchmark/results/call_protocol_exploratory_2026-11-04.json +3947 -0
  41. data/benchmark/results/call_protocol_profile_2026-11-04.json +383 -0
  42. data/benchmark/results/call_protocol_ruby_2026-11-04.json +1213 -0
  43. data/benchmark/results/call_protocol_spinel_2026-11-04.json +913 -0
  44. data/benchmark/results/call_types_ruby_2026-11-04.json +1212 -0
  45. data/benchmark/results/call_types_spinel_2026-11-04.json +923 -0
  46. data/benchmark/results/efflorescence-m1-cruby.json +799 -0
  47. data/benchmark/results/efflorescence-m1-spinel.json +799 -0
  48. data/benchmark/results/efflorescence-m2-bulk-loop.json +820 -0
  49. data/benchmark/results/efflorescence-m2-i32-cruby.json +799 -0
  50. data/benchmark/results/efflorescence-m2-i32-spinel.json +799 -0
  51. data/benchmark/results/efflorescence-m2-memory.json +408 -0
  52. data/benchmark/results/generated_guards_exploratory_2026-11-04.json +1225 -0
  53. data/benchmark/results/generated_guards_profile_2026-11-04.json +592 -0
  54. data/benchmark/results/generated_guards_spinel_2026-11-04.json +1650 -0
  55. data/benchmark/results/generated_guards_validation_2026-11-04.json +256 -0
  56. data/benchmark/results/inlining_engines_2026-11-04.json +241 -0
  57. data/benchmark/results/inlining_ruby_2026-11-04.json +1213 -0
  58. data/benchmark/results/inlining_spinel_2026-11-04.json +893 -0
  59. data/benchmark/results/operand_decode_exploratory_2026-11-04.json +1319 -0
  60. data/benchmark/results/operand_decode_ruby_2026-11-04.json +1213 -0
  61. data/benchmark/results/operand_decode_spinel_2026-11-04.json +924 -0
  62. data/benchmark/results/selective_reset_spinel_2026-11-04.json +454 -0
  63. data/benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json +2679 -0
  64. data/benchmark/results/spinel_fetch_root_patch_2026-11-04.json +4523 -0
  65. data/benchmark/results/while_final_compiler_comparison_2026-11-04.json +324 -0
  66. data/benchmark/results/while_patched_external_2026-11-04.json +220 -0
  67. data/benchmark/results/while_user_unpatched_2026-11-04.json +230 -0
  68. data/benchmark/summarize_call_profile.py +54 -0
  69. data/benchmark/validate_m1_eh.rb +34 -0
  70. data/benchmark/validate_m2.rb +119 -0
  71. data/benchmark/validate_m3.rb +44 -0
  72. data/benchmark/validate_m4.rb +95 -0
  73. data/benchmark/validate_m5.rb +108 -0
  74. data/docs/adr/0001-efflorescence-m1-control-and-eh.md +319 -0
  75. data/docs/adr/0002-efflorescence-m2-memory-and-globals.md +185 -0
  76. data/docs/adr/0003-efflorescence-m3-host-and-indirect-calls.md +228 -0
  77. data/docs/adr/0004-efflorescence-m4-i64.md +202 -0
  78. data/docs/adr/0005-efflorescence-m5-floating-point.md +127 -0
  79. data/docs/adr/0006-efflorescence-m6-coverage-parity.md +101 -0
  80. data/docs/efflorescence-call-arities.md +115 -0
  81. data/docs/efflorescence-call-investigation.md +155 -0
  82. data/docs/efflorescence-call-transfer.md +128 -0
  83. data/docs/efflorescence-call-types.md +102 -0
  84. data/docs/efflorescence-coverage-ja.md +351 -0
  85. data/docs/efflorescence-generated-c-guards.md +405 -0
  86. data/docs/efflorescence-inlining.md +165 -0
  87. data/docs/efflorescence-ja.md +155 -0
  88. data/docs/efflorescence-m1.md +160 -0
  89. data/docs/efflorescence-m2.md +233 -0
  90. data/docs/efflorescence-m3.md +131 -0
  91. data/docs/efflorescence-m4.md +88 -0
  92. data/docs/efflorescence-m5.md +82 -0
  93. data/docs/efflorescence-m6.md +95 -0
  94. data/docs/efflorescence-operand-decoding.md +105 -0
  95. data/docs/efflorescence-phase2-ja.md +225 -0
  96. data/docs/efflorescence-phase2.md +240 -0
  97. data/docs/efflorescence-register-initialization.md +75 -0
  98. data/docs/efflorescence.md +144 -0
  99. data/docs/spinel-string-aset-inplace-proposal.md +200 -0
  100. data/lib/wardite/alu_f32.generated.rb +1 -0
  101. data/lib/wardite/alu_f64.generated.rb +1 -0
  102. data/lib/wardite/alu_i32.generated.rb +14 -9
  103. data/lib/wardite/alu_i64.generated.rb +18 -20
  104. data/lib/wardite/cli/cli.rb +61 -28
  105. data/lib/wardite/const.rb +1 -0
  106. data/lib/wardite/efflorescence/float_arithmetic.rb +216 -0
  107. data/lib/wardite/efflorescence/i64_arithmetic.rb +257 -0
  108. data/lib/wardite/efflorescence/inspection.rb +165 -0
  109. data/lib/wardite/efflorescence/ir.rb +1151 -0
  110. data/lib/wardite/efflorescence/optimizer.rb +580 -0
  111. data/lib/wardite/efflorescence/register_validation.rb +290 -0
  112. data/lib/wardite/efflorescence/store_access.rb +271 -0
  113. data/lib/wardite/efflorescence/translator.rb +859 -0
  114. data/lib/wardite/efflorescence/vm.rb +1006 -0
  115. data/lib/wardite/efflorescence/wasi.rb +108 -0
  116. data/lib/wardite/efflorescence.rb +11 -0
  117. data/lib/wardite/errors.rb +20 -0
  118. data/lib/wardite/float_bits.rb +46 -0
  119. data/lib/wardite/instruction.rb +35 -4
  120. data/lib/wardite/leb128.rb +33 -12
  121. data/lib/wardite/load.rb +203 -138
  122. data/lib/wardite/value.rb +169 -175
  123. data/lib/wardite/version.rb +1 -1
  124. data/lib/wardite/wasi/consts.rb +1 -0
  125. data/lib/wardite/wasm_module.rb +6 -3
  126. data/lib/wardite.rb +184 -70
  127. data/rbs_collection.lock.yaml +36 -96
  128. data/scripts/gen_alu.rb +66 -10
  129. data/sig/generated/wardite/cli/cli.rbs +8 -6
  130. data/sig/generated/wardite/const.rbs +2 -0
  131. data/sig/generated/wardite/efflorescence/float_arithmetic.rbs +65 -0
  132. data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +99 -0
  133. data/sig/generated/wardite/efflorescence/inspection.rbs +64 -0
  134. data/sig/generated/wardite/efflorescence/ir.rbs +881 -0
  135. data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
  136. data/sig/generated/wardite/efflorescence/register_validation.rbs +76 -0
  137. data/sig/generated/wardite/efflorescence/store_access.rbs +134 -0
  138. data/sig/generated/wardite/efflorescence/translator.rbs +214 -0
  139. data/sig/generated/wardite/efflorescence/vm.rbs +179 -0
  140. data/sig/generated/wardite/efflorescence/wasi.rbs +47 -0
  141. data/sig/generated/wardite/errors.rbs +12 -0
  142. data/sig/generated/wardite/float_bits.rbs +30 -0
  143. data/sig/generated/wardite/instruction.rbs +22 -1
  144. data/sig/generated/wardite/leb128.rbs +3 -1
  145. data/sig/generated/wardite/load.rbs +29 -4
  146. data/sig/generated/wardite/value.rbs +70 -11
  147. data/sig/generated/wardite/wasi/consts.rbs +2 -0
  148. data/sig/generated/wardite.rbs +49 -12
  149. data/sig/vernier.rbs +2 -2
  150. data/spinel/README.md +30 -0
  151. data/spinel/bin/wardite.rb +6 -0
  152. data/spinel/spin.toml +7 -0
  153. metadata +126 -3
@@ -0,0 +1,500 @@
1
+ # Wardite i32 benchmark
2
+
3
+ Run `ruby benchmark/compare.rb` to compare the **new Efflorescence VM on Spinel,
4
+ Wasmtime and iwasm** on the same workload. Old-VM and CRuby/YJIT runners can be
5
+ enabled in the script. See [Run](#run) for the complete
6
+ matrix and options. The scripts below provide additional optimization-specific
7
+ comparisons.
8
+
9
+ ## M2 memory and global validation
10
+
11
+ ```sh
12
+ bundle exec ruby -Ilib benchmark/validate_m2.rb
13
+ RUNS=7 WARMUPS=2 ROUNDS=1000 bundle exec ruby benchmark/measure_m2.rb
14
+ ```
15
+
16
+ The measurement script builds a Spinel worker and runs CRuby and Spinel, checking
17
+ independent checksums for array scans, overlapping copy/fill, global updates and
18
+ repeated passive-segment initialization. Load/translation and execution times
19
+ are separate; samples alternate runtime order. `M2_SPINEL_WORKER=/path/to/worker`
20
+ reuses an existing worker. [Results, constraints and i32 before/after comparison](../docs/efflorescence-m2.md).
21
+
22
+ ## Investigate generated C guards
23
+
24
+ ```sh
25
+ VARIANTS=baseline,while_loop,c_root_elision,while_c_root_elision \
26
+ CLI=1 RUNS=7 WARMUPS=2 GUARDS_DIR=build/benchmark/generated-guards/final \
27
+ ruby benchmark/investigate_generated_guards.rb 5000000 123
28
+ ```
29
+
30
+ This fixes native compilation at `-O2` and compares copied sources and generated
31
+ C under `build/`. It reconstructs the old `loop do` baseline alongside the
32
+ `while true` variants; the production flat VM now uses `while true`.
33
+ It isolates `loop do` versus `while true`, and a narrowly checked removal of
34
+ duplicate fetch-receiver GC roots. Bounds/overflow checks and the collector stay
35
+ enabled. Every checksum and the separate MIR counters are verified.
36
+ `PROFILE=1` adds debug symbols and a dSYM; omit `VARIANTS` to include the slower
37
+ guarded-index experiments. Results go to `GUARDS_DIR/results.json`.
38
+ [Investigation, safety conditions, GC stress validation and profiles (日本語)](../docs/efflorescence-generated-c-guards.md).
39
+
40
+ The production while loop works with the unmodified Spinel revision pinned in
41
+ CI. The separately recorded fetch-root compiler patch is an optional local
42
+ experiment; select that compiler explicitly with `SPINEL=/path/to/bin/spinel`.
43
+ For the C root-removal ablation, use an unmodified compiler. With the patched
44
+ compiler, select `VARIANTS=baseline,while_loop`, since fetch roots are already
45
+ removed by the compiler and the C-editing variants intentionally refuse a no-op.
46
+
47
+ ## Small-function inlining
48
+
49
+ ```sh
50
+ INLINE_ABLATION=1 SPINELFLAGS=-O2 RUNS=7 WARMUPS=2 ruby benchmark/compare_call_types.rb 5000000 123
51
+ ```
52
+
53
+ This compares `--mir-disable inline` with default execution using **the same
54
+ compiled CLI and worker binaries**. Checksums are checked against an independent
55
+ reference, and separate counters verify that the leaf calls disappear. Results,
56
+ phase timings, MIR sizes and source/binary hashes are saved to
57
+ `build/benchmark/inlining/results.json`. Set `RUNTIMES=CRuby,YJIT` for Ruby runs.
58
+ [Implementation, limits and recorded results (日本語)](../docs/efflorescence-inlining.md).
59
+
60
+ Default `ruby benchmark/compare.rb` also includes inlining. To measure the actual
61
+ CALL mechanism, `compare_call_types.rb` without `INLINE_ABLATION=1` and
62
+ `investigate_calls.rb` explicitly disable inlining on versions that support it.
63
+ This keeps the historical MIR-counter equality check for commit comparisons.
64
+
65
+ ## Investigate internal call costs
66
+
67
+ To reproduce the zero/two/three-argument CALL experiment (not adopted):
68
+
69
+ ```sh
70
+ CALL_ARITIES=1 CALL_ARITY_EXPERIMENT=1 BASELINE_REF=8eb02af SPINELFLAGS=-O2 RUNS=7 WARMUPS=2 \
71
+ ruby benchmark/compare_call_types.rb 5000000 123
72
+ ```
73
+
74
+ The prototype is replayed only in a copied library under `build/`, with a patch
75
+ check and source fingerprints. Production argument transfer remains unchanged:
76
+ the best prototype still measured about 1.3% slower for one and three arguments.
77
+ This uses `i32_call_arities.wat`, disables inlining on both versions and checks
78
+ equal MIR counters as well as independent checksums. It measures worker phases
79
+ and CLI processes for every arity; four arguments exercise the generic fallback.
80
+ Results and source/binary hashes go to `build/benchmark/call-arities/results.json`.
81
+ `8eb02af` is the default baseline for `CALL_ARITIES=1` and must exist locally.
82
+ Use `RUNTIMES=CRuby,YJIT` to compare Ruby execution.
83
+ Omit `CALL_ARITY_EXPERIMENT=1` to compare the production source at each commit.
84
+ [Implementation, experiments and measurements (日本語)](../docs/efflorescence-call-arities.md).
85
+
86
+ To compare operand decoding at a fixed `-O2` against `5924537`:
87
+
88
+ ```sh
89
+ BASELINE_REF=5924537 SPINELFLAGS=-O2 RUNS=7 WARMUPS=2 ruby benchmark/compare_call_types.rb 5000000 123
90
+ ```
91
+
92
+ RETURN/BR skip unused b/c words; COPY, EQZ and conditional branches skip c.
93
+ The four-word layout and MIR counts are unchanged. Spinel `call_identity`
94
+ execution fell by 8.3%, `call_mix` by 4.4%, and CLI `call_mix` by 6.4%.
95
+ [Implementation, tests, exploratory variants and all samples (日本語)](../docs/efflorescence-operand-decoding.md).
96
+
97
+ The subsequent argument-transfer / pool-index comparison uses `83a4b9c`:
98
+
99
+ ```sh
100
+ BASELINE_REF=83a4b9c RUNS=7 WARMUPS=2 ruby benchmark/compare_call_types.rb 5000000 123
101
+ ```
102
+
103
+ Spinel execution fell by 9.8% for `call_identity`, 9.5% for `call_add_one`,
104
+ and 5.4% for `call_mix`; full CLI `call_mix` time fell by 7.7%.
105
+ [Design, unsuccessful experiments, profiler results and samples (日本語)](../docs/efflorescence-call-transfer.md).
106
+ `PROFILE_DIR` can select a separate output directory for `build_call_profile.rb`.
107
+
108
+ To compare the CALL/RETURN type-preservation change against the independently
109
+ built previous commit (`fa4b14e`, required locally):
110
+
111
+ ```sh
112
+ RUNS=7 WARMUPS=2 ruby benchmark/compare_call_types.rb 5000000 123
113
+ RUNTIMES=CRuby,YJIT RUNS=3 WARMUPS=1 ruby benchmark/compare_call_types.rb 100000 123
114
+ ```
115
+
116
+ `BASELINE_REF` chooses another baseline. Each version gets a separate source
117
+ snapshot, CLI and phase worker. Cached binaries are reused only after checking
118
+ source/compiler/flag fingerprints and binary SHA256. Every measured checksum
119
+ and each version's MIR metrics are verified; counters run outside timing.
120
+ Spinel `call_mix` execution fell from 590.542 to 499.544 ms (15.4%), and CLI
121
+ process time from 634.154 to 519.719 ms (18.0%).
122
+ [Design, generated C, validation and all samples (日本語)](../docs/efflorescence-call-types.md).
123
+
124
+ ```sh
125
+ RUNS=7 WARMUPS=2 ruby benchmark/investigate_calls.rb 1000000 123
126
+ ruby benchmark/build_call_profile.rb
127
+ ```
128
+
129
+ The first script compares empty/identity/add/mix loops and matching inline
130
+ controls with five frame strategies on Spinel. `locals_only` is the production
131
+ engine; `full_reset` restores the old reset loop in a copied library, keeping
132
+ the constructor and load-time validation identical. Experimental changes are made
133
+ only in copied libraries under `build/benchmark/call-cost/`. Every timed result
134
+ is checked against an independent reference. MIR counters and native allocation
135
+ reports are collected in separate, untimed processes.
136
+
137
+ The second script saves generated C, obtains runtime/link settings from Spinel's
138
+ `--print-build`, and compiles with `-O2 -g -fno-omit-frame-pointer`. On macOS it
139
+ also retains the object file and creates a dSYM for Instruments.
140
+
141
+ [Investigation, results and profiling commands (日本語)](../docs/efflorescence-call-investigation.md).
142
+ The fixture-specific `metadata_only` experiment is not a supported engine mode.
143
+
144
+ For the production selective-initialization comparison (five million rounds):
145
+
146
+ ```sh
147
+ VARIANTS=full_reset,locals_only EXPORTS=inline_mix,call_mix \
148
+ RUNS=7 WARMUPS=2 ruby benchmark/investigate_calls.rb 5000000 123
149
+ ```
150
+
151
+ Spinel `call_mix` execution averaged 727.817 → 603.672 ms (17.1% less time),
152
+ with matching checksums and unchanged MIR dispatch counts.
153
+ [Selective initialization: design, validation and samples (日本語)](../docs/efflorescence-register-initialization.md).
154
+
155
+ ## Phase 2 optimization comparison
156
+
157
+ The Phase 2 sample below predates the integer-literal dispatch follow-up; see
158
+ [the isolated dispatch comparison](#integer-literal-dispatch) for that change.
159
+
160
+ ```sh
161
+ ruby benchmark/compare_optimizations.rb 100000 123
162
+ # Also measure each feature independently disabled:
163
+ ABLATIONS=1 RUNS=3 WARMUPS=1 ruby benchmark/compare_optimizations.rb 100000 123
164
+ ```
165
+
166
+ Requires Ruby, Spinel/C toolchain, make and wasm-tools. The script builds the CLI
167
+ and phase worker, verifies every measured CLI/worker pair against the independent
168
+ reference, collects detailed counters in separate untimed runs, and measures
169
+ CRuby, available YJIT and Spinel. Defaults: five samples after two warmups.
170
+ `unoptimized` disables all Phase 2 features in the current code, while
171
+ `optimized` enables all of them. Each-feature-off measurements keep the other
172
+ features enabled; their effects interact (e.g. disabling immediates also prevents
173
+ immediate shift/XOR fusion), so speedups are not additive.
174
+
175
+ The report `build/benchmark/optimizations.json` contains raw samples, phase and
176
+ whole-process means, CRuby execution allocations and per-opcode counters.
177
+ Time measurement does not enable MIR counters. Both phase and CLI measurements
178
+ include the same Ruby-facing boxed return boundary. Spinel allocations are `n/a`.
179
+ The shared phase loader creates the default runtime, then the selected MIR VM is
180
+ constructed in the MIR phase; the fixture has no start function. Phase timing
181
+ uses a separate executable, whose Spinel inference can differ from the CLI.
182
+ `SPINEL` and `SPINELFLAGS` choose the compiler/flags (default `-O2`).
183
+
184
+ For an independently built Phase 1 baseline (requires commit `67fbfae` locally):
185
+
186
+ ```sh
187
+ mkdir -p build/phase1 build/benchmark
188
+ git archive 67fbfae | tar -x -C build/phase1
189
+ make -C build/phase1 spinel
190
+ spinel -I build/phase1/lib --strict-require -O2 build/phase1/benchmark/engine_phases.rb -o build/benchmark/phase1-engine-phases
191
+ PHASE1_ROOT=build/phase1 PHASE1_BIN=build/phase1/build/wardite PHASE1_WORKER=build/benchmark/phase1-engine-phases ruby benchmark/compare_optimizations.rb 100000 123
192
+ ```
193
+
194
+ The native baseline defaults to `build/benchmark/phase1-wardite` when
195
+ `PHASE1_BIN` is omitted. The archived CRuby source runs independently, rather
196
+ than using the current engine's disabled-pass mode as a substitute for Phase 1.
197
+ [Implementation and metric definitions](../docs/efflorescence-phase2.md)
198
+ ([日本語](../docs/efflorescence-phase2-ja.md)).
199
+
200
+ ### Phase 2 sample (2026-11-04)
201
+
202
+ macOS arm64, CRuby 4.0.9 (`3e93b23afc`), Spinel `2026.10.25+1967`
203
+ (`6e7fc1355`, Apple clang 21.0.0), `-O2` and default integer overflow checks.
204
+ 100,000 rounds, seed 123, five samples after two warmups. The Phase 1 baseline
205
+ is the archived source and independent native executables from `67fbfae`.
206
+ All 18 CLI/worker pairs matched checksum `3870791521` before timing, and every
207
+ timed sample was checked again. Timings are milliseconds, not speedup factors.
208
+
209
+ Whole CLI process time:
210
+
211
+ | Runtime | Phase 1 inline | Phase 2 inline | Phase 1 call | Phase 2 call |
212
+ | --- | ---: | ---: | ---: | ---: |
213
+ | CRuby | 414.82 | 317.33 | 668.59 | 575.44 |
214
+ | CRuby + YJIT | 215.49 | 159.61 | 336.77 | 235.56 |
215
+ | Spinel | 62.58 | 17.83 | 86.63 | 30.71 |
216
+
217
+ Execution phase only (separate worker binaries):
218
+
219
+ | Runtime | Phase 1 inline | Phase 2 inline | Phase 1 call | Phase 2 call |
220
+ | --- | ---: | ---: | ---: | ---: |
221
+ | CRuby | 393.16 | 253.94 | 609.77 | 500.60 |
222
+ | CRuby + YJIT | 153.46 | 65.38 | 231.06 | 141.26 |
223
+ | Spinel | 30.98 | 12.25 | 49.03 | 23.33 |
224
+
225
+ Current-code unoptimized execution was also measured: Spinel 33.07/56.26 ms,
226
+ CRuby 375.25/667.11 ms, YJIT 126.85/241.11 ms (inline/call). This is distinct
227
+ from the independently compiled Phase 1 baseline. Phase 2 MIR construction
228
+ averaged 0.58/0.61 ms on CRuby, 23.25/23.30 ms with YJIT, and 0.17/0.18 ms
229
+ on Spinel. This cost matters for short workloads.
230
+
231
+ CRuby's `call_mix` execution allocations fell from 200,074 in current-code
232
+ unoptimized mode to 79 with all features enabled. These counts include API
233
+ setup and one boxed return, and exclude module loading/translation. They do
234
+ not imply the same total allocation count on Spinel; instrumented MIR separately
235
+ confirmed Frame allocations falling from 100,001 to 2 on both runtimes.
236
+
237
+ An exploratory each-feature-off run (three CLI samples after one warmup) gave
238
+ the following Spinel process times. These use the same CLI boundary as above;
239
+ they are diagnostic observations, not independent additive speedups:
240
+
241
+ | Disabled feature | inline | call |
242
+ | --- | ---: | ---: |
243
+ | None | 16.43 | 30.18 |
244
+ | COPY reduction | 19.95 | 34.55 |
245
+ | Immediates | 17.52 | 31.82 |
246
+ | Branch fusion | 16.51 | 31.75 |
247
+ | Superinstructions | 17.81 | 32.10 |
248
+ | Flat code | 40.05 | 60.38 |
249
+ | Frame reuse | 15.75 | 33.61 |
250
+
251
+ Flat code had the clearest Spinel benefit. Frame reuse primarily helped call
252
+ workloads. Some CRuby/YJIT variants were within noise or faster with an
253
+ individual feature disabled; feature defaults prioritize Spinel while retaining
254
+ the individual controls. Accumulators and basic-block dispatch are deferred.
255
+ Raw local reports are `build/benchmark/optimizations.json` (five-sample run)
256
+ and `build/benchmark/optimizations-experiment.json` (exploratory run).
257
+
258
+ ### Integer-literal dispatch
259
+
260
+ ```sh
261
+ ruby benchmark/compare_dispatch.rb 100000 123
262
+ RUNTIMES=Spinel ruby benchmark/compare_dispatch.rb 1000000 123
263
+ ```
264
+
265
+ The script compares `when Opcode::NAME` with `when <integer literal>` while
266
+ keeping all Phase 2 features enabled in both variants. It creates a temporary
267
+ constant-label baseline from the current source's annotated dispatch labels,
268
+ builds both CLI and worker with the same Spinel/flags, and verifies every
269
+ CLI/worker pair against the independent reference. Paired samples alternate
270
+ order; all timed invocations are checked again. Defaults are five samples after
271
+ two warmups. `RUNTIMES` can select `Spinel`, `CRuby`, and/or available `YJIT`,
272
+ comma-separated. Raw samples are saved to `build/benchmark/dispatch.json`.
273
+
274
+ On 2026-11-04, with the same CRuby/Spinel toolchain and `-O2` as above,
275
+ 100,000 rounds and seed 123, five measured processes after two warmups gave
276
+ these execution-phase means (milliseconds):
277
+
278
+ | Runtime | Constant inline | Literal inline | Constant call | Literal call |
279
+ | --- | ---: | ---: | ---: | ---: |
280
+ | CRuby | 254.08 | 119.21 | 492.31 | 303.84 |
281
+ | CRuby + YJIT | 65.93 | 58.71 | 140.36 | 129.40 |
282
+ | Spinel | 10.11 | 9.13 | 25.93 | 21.21 |
283
+
284
+ The short Spinel constant-label call samples had a 6.53 ms standard deviation,
285
+ so a longer Spinel-only run used **1,000,000 rounds**, seed 123. All calls
286
+ returned `1259766978`. Five samples after two warmups gave:
287
+
288
+ | Spinel export | Constant execution | Literal execution | Time reduction |
289
+ | --- | ---: | ---: | ---: |
290
+ | `inline_mix` | 100.43 ± 0.49 ms | 90.68 ± 0.28 ms | 9.7% |
291
+ | `call_mix` | 229.76 ± 0.30 ms | 209.93 ± 0.94 ms | 8.6% |
292
+
293
+ Uncertainty is the sample standard deviation, not a confidence interval.
294
+ Whole CLI process times in that longer run were 104.94 → 97.33 ms for inline
295
+ and 248.37 → 221.64 ms for call. Thus this change gives a further measured
296
+ Spinel improvement beyond the other Phase 2 optimizations; the short call run's
297
+ larger apparent gain should not be treated as the stable speedup.
298
+ Local raw reports are `build/benchmark/dispatch-100k.json` and
299
+ `build/benchmark/dispatch-million.json` (also the latest `dispatch.json`).
300
+
301
+ ## Compare the stack and Efflorescence engines
302
+
303
+ ```sh
304
+ ruby benchmark/compare_engines.rb 100000 123
305
+ # Optional sample counts (default: 5 samples after 2 warmups):
306
+ RUNS=3 WARMUPS=1 ruby benchmark/compare_engines.rb 100000 123
307
+ ```
308
+
309
+ Requires Ruby, Spinel/C toolchain, make and wasm-tools. YJIT is included when
310
+ available. The script builds both native entry points, checks **all eight Phase
311
+ 1 input cases** on both exports and both engines on every runtime against an
312
+ independent reference, then measures the requested input. A mismatch aborts.
313
+
314
+ Results include whole CLI process time and separate load, MIR translation and
315
+ execution times from `engine_phases.rb`, compiled unchanged by Spinel. Phase
316
+ timings come from a separate process per sample, with one call per process;
317
+ they include frame setup and the final Ruby-facing result box. The loader phase
318
+ creates the shared instance with the default runtime; the fixture has no start
319
+ function, so it executes no guest instructions. For Efflorescence, the next
320
+ phase constructs the selected VM from that instance (including a second, empty
321
+ Runtime setup for stack samples). End-to-end samples use the real
322
+ CLI with `--new-engine` and therefore include normal engine selection, startup,
323
+ load, translation, execution and output. Warmups are separate processes, so YJIT
324
+ compiles anew for each sample. Native compilation is outside measurement.
325
+ Phase values are diagnostic and do not sum to the CLI time: they use a separate
326
+ entry point, which can also change Spinel's whole-program type inference.
327
+
328
+ Raw samples and means are saved to `build/benchmark/engines.json`. `SPINEL` and
329
+ `SPINELFLAGS` can select the compiler and flags (default `-O2`, with the default
330
+ overflow checks enabled). [Engine design and scope](../docs/efflorescence.md).
331
+
332
+ ### Phase 1 sample (2026-11-03)
333
+
334
+ macOS arm64, CRuby 4.0.9 (`3e93b23afc`), Spinel `2026.10.25+1967`
335
+ (`6e7fc1355`, Apple clang 21.0.0), `-O2`, default overflow checks, 100,000
336
+ rounds, seed 123. Five measured processes per command after two warmups.
337
+ All eight acceptance input cases passed on all six engine/runtime combinations
338
+ before measurement. Every measured invocation returned unsigned checksum
339
+ `3870791521`, printed by the CLI as `I32(-424175775)`.
340
+
341
+ Mean whole CLI process time, in milliseconds:
342
+
343
+ | Runtime | Stack inline | Efflorescence inline | Stack call | Efflorescence call |
344
+ | --- | ---: | ---: | ---: | ---: |
345
+ | CRuby | 1032.56 | 409.63 | 1218.78 | 656.89 |
346
+ | CRuby + YJIT | 488.49 | 198.24 | 627.45 | 285.86 |
347
+ | Spinel | 341.05 | 59.10 | 405.80 | 83.69 |
348
+
349
+ Mean execution phase only, in milliseconds, from the separate phase runner:
350
+
351
+ | Runtime | Stack inline | Efflorescence inline | Stack call | Efflorescence call |
352
+ | --- | ---: | ---: | ---: | ---: |
353
+ | CRuby | 968.36 | 348.32 | 1157.74 | 598.88 |
354
+ | CRuby + YJIT | 423.70 | 119.66 | 550.27 | 208.93 |
355
+ | Spinel | 318.36 | 30.08 | 370.79 | 48.55 |
356
+
357
+ Efflorescence MIR construction averaged 0.12 ms on CRuby, 14.54 ms with YJIT
358
+ (including JIT work in that phase), and 0.03 ms on Spinel. Loading averaged
359
+ 0.11–0.38 ms without YJIT, and 3.3–3.4 ms with it. These are observations for
360
+ this machine and input; rerun before comparing with older samples below.
361
+
362
+ The original `compare.rb` below remains available for comparisons with external
363
+ Wasm runtimes.
364
+
365
+ `i32_mix.wat` provides two exports with the same `(rounds: i32, seed: i32) -> i32`
366
+ signature and checksum:
367
+
368
+ - `inline_mix`: dependent integer operations directly inside a loop. Exercises
369
+ opcode dispatch, local variables, arithmetic, shifts, XOR, and branches.
370
+ - `call_mix`: the same calculation through an internal Wasm function on each
371
+ iteration. Adds argument passing and call-frame creation/return.
372
+
373
+ The calculation mixes a changing 32-bit value using XOR, shifts, multiplication,
374
+ and addition. Every iteration contributes to the returned checksum. Work size
375
+ and seed are runtime arguments. There are no imports, WASI calls, or I/O inside
376
+ Wasm, and no growing memory allocation by the guest program. The stack VM
377
+ allocates value objects and, for `call_mix`, frames during interpretation;
378
+ Efflorescence keeps i32 values unboxed and reuses call frames.
379
+
380
+ ## Run
381
+
382
+ Requirements: Ruby, Spinel and its C toolchain, `make`, `wasm-tools`,
383
+ `wasmtime`, `iwasm` (WAMR with interpreter support), and `hyperfine` on PATH.
384
+ No Bundler dependencies are needed for the comparison script.
385
+ Run from the repository root:
386
+
387
+ ```sh
388
+ ruby benchmark/compare.rb
389
+ # Adjust work size and seed:
390
+ ruby benchmark/compare.rb 200000 42
391
+ # Adjust sample counts (default: 5 samples after 2 warmups):
392
+ RUNS=3 WARMUPS=1 ruby benchmark/compare.rb 100000 123
393
+ ```
394
+
395
+ The script compiles the WAT and the Spinel CLI, computes an independent Ruby
396
+ reference, and checks all enabled command results before timing. The current
397
+ selection is New VM / Spinel, iwasm, Wasmtime (Pulley) and Wasmtime: **8 commands**
398
+ across both exports. Uncomment the CRuby/YJIT and Old VM runner definitions in
399
+ `compare.rb` to enable the full nine-configuration, **18-command** matrix below.
400
+ YJIT support is required only when its runner is enabled.
401
+
402
+ | Engine | Execution configurations |
403
+ | --- | --- |
404
+ | Old VM (`Wardite::Runtime`) | CRuby (YJIT disabled), CRuby + YJIT, Spinel |
405
+ | New VM (`Wardite::Efflorescence::VM`) | CRuby (YJIT disabled), CRuby + YJIT, Spinel; `--new-engine`, default optimizations |
406
+ | iwasm / WAMR | Explicit interpreter mode (`--interp`) |
407
+ | Wasmtime (Pulley) | `--target pulley64 -C cache=n` |
408
+ | Wasmtime | Native compilation, `-C cache=n` |
409
+
410
+ Hyperfine command names distinguish `Old VM` and `New VM`. A mismatch,
411
+ unavailable enabled YJIT or a missing required runtime stops the run.
412
+ Defaults: 100,000 rounds,
413
+ seed 123456789, two warmup processes, and five measured processes per command.
414
+ The expected checksum with these defaults is `I32(261279018)`.
415
+ Wardite and Wasmtime display a signed decimal i32; iwasm displays the same
416
+ unsigned bits as hexadecimal. Verification accounts for both representations,
417
+ including values with the high bit set.
418
+
419
+ Results are written to `build/benchmark/results.json` (overwritten each run).
420
+ The Spinel compiler build and reference/result checks are outside the timed commands.
421
+ Hyperfine runs commands without a shell. Wasmtime runs with `-C cache=n`, so
422
+ each process compiles the module rather than reusing a compiled-module cache.
423
+
424
+ For a single invocation after building:
425
+
426
+ ```sh
427
+ ruby -Ilib exe/wardite --no-wasi --invoke inline_mix -- build/benchmark/i32_mix.wasm 100000 123456789
428
+ ruby -Ilib exe/wardite --new-engine --no-wasi --invoke inline_mix -- build/benchmark/i32_mix.wasm 100000 123456789
429
+ ruby --yjit -Ilib exe/wardite --no-wasi --invoke inline_mix -- build/benchmark/i32_mix.wasm 100000 123456789
430
+ ruby --yjit -Ilib exe/wardite --new-engine --no-wasi --invoke inline_mix -- build/benchmark/i32_mix.wasm 100000 123456789
431
+ ./build/wardite --no-wasi --invoke inline_mix -- build/benchmark/i32_mix.wasm 100000 123456789
432
+ ./build/wardite --new-engine --no-wasi --invoke inline_mix -- build/benchmark/i32_mix.wasm 100000 123456789
433
+ iwasm --interp -f inline_mix build/benchmark/i32_mix.wasm 100000 123456789
434
+ wasmtime run --target pulley64 -C cache=n --invoke inline_mix build/benchmark/i32_mix.wasm 100000 123456789
435
+ wasmtime run -C cache=n --invoke inline_mix build/benchmark/i32_mix.wasm 100000 123456789
436
+ ```
437
+
438
+ ## Interpret results
439
+
440
+ These are **whole CLI process wall times**: Ruby/native startup, module loading,
441
+ execution, and printing the checksum. Wasmtime also compiles the Wasm module
442
+ in each timed process; its compiled-module cache is explicitly disabled. They measure the cost of running this
443
+ program through each runtime's CLI, rather than execution-loop throughput alone.
444
+ Hyperfine warmups start separate processes; YJIT compiles anew in each process.
445
+ Increase rounds to reduce the share spent on startup/loading, and keep the same
446
+ rounds and seed across comparisons. Zero rounds return the seed without mixing
447
+ and can be used to inspect startup/loading overhead.
448
+
449
+ Compare runtimes **within the same export**. Compare the two exports within a
450
+ runtime to examine the additional cost of Wasm calls. An optimizing compiler
451
+ such as Wasmtime may inline the helper, so its two exports need not retain the
452
+ same call overhead that an interpreter does. This workload covers i32
453
+ execution and calls; it does not measure memory instructions, floating point,
454
+ WASI, or arbitrary real-world programs.
455
+
456
+ Zero/one rounds and high-bit seeds can be checked with the same script; each
457
+ checksum is validated across both Wardite VMs, iwasm and both Wasmtime modes.
458
+
459
+ ### Full engine comparison (2026-11-04)
460
+
461
+ Verified with the default input (100,000 rounds, seed 123456789), five measured
462
+ processes after two warmups. All 18 preflight results matched the independent
463
+ reference checksum `261279018`, and every measured process exited successfully.
464
+ Zero rounds and one round with seed `4294967295` were also checked on all nine
465
+ configurations. Toolchain: macOS arm64, CRuby 4.0.9, Spinel `2026.10.25+1967`
466
+ (`6e7fc1355`, `-O2`, default overflow checks), Wasmtime 49.0.0, iwasm 2.4.5,
467
+ Hyperfine 1.19.0.
468
+
469
+ Whole process time, mean ± sample standard deviation in milliseconds:
470
+
471
+ | Engine / runtime | `inline_mix` | `call_mix` |
472
+ | --- | ---: | ---: |
473
+ | Old VM / CRuby | 1039.26 ± 6.84 | 1230.13 ± 7.00 |
474
+ | New VM / CRuby | 181.23 ± 3.26 | 377.69 ± 31.42 |
475
+ | Old VM / CRuby + YJIT | 493.67 ± 5.19 | 621.38 ± 3.00 |
476
+ | New VM / CRuby + YJIT | 145.85 ± 0.60 | 215.39 ± 1.60 |
477
+ | Old VM / Spinel | 341.02 ± 4.73 | 401.50 ± 0.78 |
478
+ | New VM / Spinel | 12.95 ± 0.26 | 25.71 ± 0.28 |
479
+ | iwasm (WAMR interpreter) | 5.13 ± 0.22 | 5.59 ± 0.26 |
480
+ | Wasmtime (Pulley) | 8.11 ± 0.28 | 9.32 ± 0.14 |
481
+ | Wasmtime | 6.31 ± 0.08 | 6.63 ± 0.24 |
482
+
483
+ Raw samples are in `build/benchmark/results.json`. These include startup and
484
+ loading, plus compilation for Wasmtime and MIR translation for Efflorescence;
485
+ they are not execution-loop-only measurements.
486
+
487
+ ### Sample run (2026-11-03)
488
+
489
+ macOS arm64, CRuby 4.0.8, Spinel `2026.10.25+1967` (`6e7fc1355`, Apple clang
490
+ 21.0.0), `-O2 --int-overflow=promote`, Wasmtime 49.0.0 (`-C cache=n`),
491
+ 100,000 rounds, seed 123456789. Mean wall
492
+ time ± standard deviation over five runs (two warmup processes):
493
+
494
+ | Export | CRuby | CRuby + YJIT | Spinel | Wasmtime |
495
+ | --- | ---: | ---: | ---: | ---: |
496
+ | `inline_mix` | 682.2 ± 7.1 ms | 275.0 ± 11.2 ms | 167.1 ± 2.2 ms | 4.7 ± 0.2 ms |
497
+ | `call_mix` | 811.1 ± 6.7 ms | 357.5 ± 3.2 ms | 204.7 ± 1.4 ms | 5.3 ± 0.3 ms |
498
+
499
+ All eight commands returned `I32(261279018)`. These numbers describe this machine and
500
+ CLI workload, and should be remeasured when the runtime or compiler changes.
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ask the installed compiler for its runtime, package objects, defines and C
4
+ # flags. Compile the saved C ourselves, keeping C source locations in DWARF.
5
+ require "fileutils"
6
+ require "json"
7
+ require "open3"
8
+ require "shellwords"
9
+
10
+ Dir.chdir(File.expand_path("..", __dir__))
11
+ output = File.expand_path(ENV.fetch("PROFILE_DIR", "build/benchmark/call-cost/profile"))
12
+ FileUtils.mkdir_p(output)
13
+ compiler = Shellwords.split(ENV.fetch("SPINEL", "spinel"))
14
+ source = "#{output}/worker.c"
15
+ binary = "#{output}/worker"
16
+ command = [*compiler, "-Ilib", "--strict-require", "-O2", "--profile", "--no-line-map",
17
+ "-c", "--force", "benchmark/call_cost_worker.rb", "-o", source, "--print-build"]
18
+ stdout, stderr, status = Open3.capture3(*command)
19
+ File.write("#{output}/spinel.log", stderr)
20
+ abort "Spinel failed; see #{output}/spinel.log" unless status.success?
21
+ File.write("#{output}/ingredients.txt", stdout)
22
+ ingredients = stdout.lines.map { |line| line.strip.split(" ", 2) }
23
+ raise "Spinel did not preserve the requested C file" unless File.exist?(source) && ingredients.include?(["source", source])
24
+ known = %w[cflag include define source link runtime lib]
25
+ raise "Unknown build ingredient" unless ingredients.all? { |kind, value| known.include?(kind) && value }
26
+ cflags = ingredients.filter_map do |kind, value|
27
+ kind == "include" ? "-I#{value}" : (%w[cflag define].include?(kind) ? value : nil)
28
+ end
29
+ links = ingredients.filter_map { |kind, value| value if %w[link runtime lib].include?(kind) }
30
+ cc = Shellwords.split(ENV.fetch("CC", "clang"))
31
+ object = "#{output}/worker.o"
32
+ compile = [*cc, "-O2", "-g", "-fno-omit-frame-pointer", *cflags, "-c", source, "-o", object]
33
+ link = [*cc, "-g", object, *links, "-o", binary]
34
+ File.write("#{output}/compile-command.json", JSON.pretty_generate({compile: compile, link: link}) + "\n")
35
+ abort "C compilation failed; see #{output}/clang.log" unless system(*compile, out: "#{output}/clang.log", err: [:child, :out])
36
+ abort "C link failed; see #{output}/link.log" unless system(*link, out: "#{output}/link.log", err: [:child, :out])
37
+ if RUBY_PLATFORM.include?("darwin")
38
+ # Keep worker.o: Mach-O's debug map points into it until dsymutil bundles DWARF.
39
+ FileUtils.rm_rf("#{binary}.dSYM")
40
+ abort "dsymutil failed" unless system("dsymutil", binary, out: "#{output}/dsymutil.log", err: [:child, :out])
41
+ end
42
+ puts "Saved generated C, build ingredients, compile command and debug binary in #{output}"
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ # rbs_inline: enabled
3
+
4
+ # Keep the same entry point for every native variant. Counters are collected in
5
+ # a separate process; they never run during a timing sample.
6
+ require "wardite"
7
+
8
+ wasm = ARGV.fetch(0)
9
+ export = ARGV.fetch(1)
10
+ rounds = ARGV.fetch(2).to_i
11
+ seed = ARGV.fetch(3).to_i
12
+ disabled = ARGV.fetch(4, "").split(",").map { |name| name.to_sym }
13
+ profile = ARGV.fetch(5, "time") == "metrics"
14
+ started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
15
+ instance = File.open(wasm, "rb") do |file|
16
+ Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false)
17
+ end
18
+ loaded = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
+ vm = Wardite::Efflorescence::VM.new(instance, disabled_optimizations: disabled, profile: profile)
20
+ translated = Process.clock_gettime(Process::CLOCK_MONOTONIC)
21
+ result = vm.call_unboxed(export, [rounds, seed]) || raise("missing checksum")
22
+ finished = Process.clock_gettime(Process::CLOCK_MONOTONIC)
23
+ puts "#{loaded - started},#{translated - loaded},#{finished - translated},#{result}"
24
+ if profile
25
+ puts vm.metrics.report
26
+ puts Wardite::Efflorescence::Inspection.new.statistics(vm.optimized_ir)
27
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "open3"
5
+ require "rbconfig"
6
+ require "shellwords"
7
+
8
+ root = File.expand_path("..", __dir__)
9
+ Dir.chdir(root)
10
+ rounds = Integer(ARGV.fetch(0, "100000"), 10)
11
+ seed = Integer(ARGV.fetch(1, "123456789"), 10)
12
+ runs = Integer(ENV.fetch("RUNS", "5"), 10)
13
+ warmups = Integer(ENV.fetch("WARMUPS", "2"), 10)
14
+ abort "usage: ruby benchmark/compare.rb [rounds: 0..2147483647] [seed: 0..4294967295]" unless
15
+ (0..2147483647).cover?(rounds) && (0..4294967295).cover?(seed)
16
+ abort "RUNS must be positive and WARMUPS must be nonnegative" unless runs > 0 && warmups >= 0
17
+
18
+ FileUtils.mkdir_p("build/benchmark")
19
+ wasm = "build/benchmark/i32_mix.wasm"
20
+ abort "WAT compilation failed" unless system("wasm-tools", "parse", "benchmark/i32_mix.wat", "-o", wasm)
21
+ abort "Spinel build failed" unless system("make", "spinel")
22
+
23
+ # Independent reference with explicit Wasm i32 wrapping after each operation.
24
+ checksum = seed
25
+ rounds.times do
26
+ checksum ^= checksum >> 13
27
+ checksum = (checksum * 1664525 + 1013904223) & 0xffffffff
28
+ checksum = (checksum ^ (checksum << 7)) & 0xffffffff
29
+ end
30
+ signed = checksum >= 0x80000000 ? checksum - 0x100000000 : checksum
31
+ expected = "return value: I32(#{signed})\n"
32
+
33
+ wardite_runners = {
34
+ # "CRuby" => [RbConfig.ruby, "--disable-yjit", "-Ilib", "exe/wardite"],
35
+ # "CRuby + YJIT" => [RbConfig.ruby, "--yjit", "-Ilib", "exe/wardite"],
36
+ "Spinel" => ["./build/wardite"]
37
+ }
38
+ runners = {}
39
+ wardite_runners.each do |runtime, command|
40
+ # runners["Old VM / #{runtime}"] = [:wardite, command]
41
+ runners["New VM / #{runtime}"] = [:wardite, command + ["--new-engine"]]
42
+ end
43
+ runners["iwasm (WAMR interpreter)"] = [:iwasm, ["iwasm", "--interp"]]
44
+ runners["Wasmtime (Pulley)"] = [:wasmtime, ["wasmtime", "run", "--target", "pulley64", "-C", "cache=n"]]
45
+ runners["Wasmtime"] = [:wasmtime, ["wasmtime", "run", "-C", "cache=n"]]
46
+ # Refuse to label an interpreted run as YJIT on a Ruby built without it.
47
+ if wardite_runners.key?("CRuby + YJIT")
48
+ output, status = Open3.capture2e(RbConfig.ruby, "--yjit", "-e", "abort 'YJIT unavailable' unless defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?")
49
+ abort output unless status.success?
50
+ end
51
+
52
+ commands = []
53
+ %w[inline_mix call_mix].each do |export|
54
+ runners.each do |name, (kind, runner)|
55
+ command = case kind
56
+ when :wasmtime
57
+ # Its CLI parses i32 arguments as signed values, with the same bits.
58
+ signed_seed = seed >= 0x80000000 ? seed - 0x100000000 : seed
59
+ runner + ["--invoke", export, wasm, rounds.to_s, signed_seed.to_s]
60
+ when :iwasm
61
+ runner + ["-f", export, wasm, rounds.to_s, seed.to_s]
62
+ else
63
+ runner + ["--no-wasi", "--invoke", export, "--", wasm, rounds.to_s, seed.to_s]
64
+ end
65
+ stdout, stderr, status = Open3.capture3(*command)
66
+ matches = case kind
67
+ when :wasmtime
68
+ stdout.strip == signed.to_s
69
+ when :iwasm
70
+ # iwasm prints the unsigned bit pattern, even when Wardite/Wasmtime
71
+ # display the same i32 as a negative signed integer.
72
+ stdout.strip == "0x%x:i32" % checksum
73
+ else
74
+ stdout.empty? && stderr == expected
75
+ end
76
+ abort "#{name}/#{export} failed: stdout=#{stdout.inspect}, stderr=#{stderr.inspect}" unless status.success? && matches
77
+ commands.concat(["--command-name", "#{name} / #{export}", Shellwords.join(command)])
78
+ end
79
+ end
80
+ puts "Verified all #{runners.size * 2} results against reference: I32(#{signed}) (rounds=#{rounds}, seed=#{seed})"
81
+ puts "Timing whole CLI processes, including startup and module loading (Wasmtime cache off, compilation included)."
82
+ version, = Open3.capture2e(RbConfig.ruby, "--version")
83
+ puts "CRuby: #{version.strip}"
84
+ {"Spinel" => Shellwords.split(ENV.fetch("SPINEL", "spinel")),
85
+ "Wasmtime" => ["wasmtime"], "iwasm" => ["iwasm"]}.each do |name, command|
86
+ output, status = Open3.capture2e(*command, "--version")
87
+ abort "Cannot identify #{name}: #{output}" unless status.success?
88
+ puts "#{name}: #{output.lines.first.to_s.strip}"
89
+ end
90
+ abort "Benchmark failed" unless system(
91
+ "hyperfine", "--shell=none", "--warmup", warmups.to_s, "--runs", runs.to_s,
92
+ "--export-json", "build/benchmark/results.json", *commands
93
+ )