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.
- checksums.yaml +4 -4
- data/LICENSE +191 -0
- data/Makefile +14 -0
- data/README.md +80 -1
- data/Rakefile +5 -0
- data/benchmark/README.md +500 -0
- data/benchmark/build_call_profile.rb +42 -0
- data/benchmark/call_cost_worker.rb +27 -0
- data/benchmark/compare.rb +93 -0
- data/benchmark/compare_call_types.rb +212 -0
- data/benchmark/compare_dispatch.rb +123 -0
- data/benchmark/compare_engines.rb +119 -0
- data/benchmark/compare_optimizations.rb +139 -0
- data/benchmark/engine_phases.rb +30 -0
- data/benchmark/figures/README.md +35 -0
- data/benchmark/figures/plot_spinel_comparison.py +137 -0
- data/benchmark/figures/spinel_new_vm_candlestick.png +0 -0
- data/benchmark/figures/spinel_new_vm_candlestick.svg +7615 -0
- data/benchmark/figures/spinel_new_vm_summary.csv +9 -0
- data/benchmark/figures/spinel_new_vm_summary.json +82 -0
- data/benchmark/float_m5.wat +42 -0
- data/benchmark/i32_call_arities.wat +89 -0
- data/benchmark/i32_calls.wat +174 -0
- data/benchmark/i32_memory.wat +58 -0
- data/benchmark/i32_mix.wat +80 -0
- data/benchmark/i64_m4.wat +55 -0
- data/benchmark/investigate_calls.rb +231 -0
- data/benchmark/investigate_generated_guards.rb +218 -0
- data/benchmark/m3_call_worker.rb +38 -0
- data/benchmark/measure_m1.rb +51 -0
- data/benchmark/measure_m2.rb +55 -0
- data/benchmark/measure_m3_calls.rb +89 -0
- data/benchmark/measure_m4.rb +134 -0
- data/benchmark/measure_m5_boundary.rb +41 -0
- data/benchmark/measure_wasi_write.rb +75 -0
- data/benchmark/optimization_worker.rb +23 -0
- data/benchmark/results/call_arities_exploratory_2026-11-04.json +4320 -0
- data/benchmark/results/call_arities_spinel_2026-11-04.json +1200 -0
- data/benchmark/results/call_cost_spinel_2026-11-04.json +2392 -0
- data/benchmark/results/call_protocol_exploratory_2026-11-04.json +3947 -0
- data/benchmark/results/call_protocol_profile_2026-11-04.json +383 -0
- data/benchmark/results/call_protocol_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/call_protocol_spinel_2026-11-04.json +913 -0
- data/benchmark/results/call_types_ruby_2026-11-04.json +1212 -0
- data/benchmark/results/call_types_spinel_2026-11-04.json +923 -0
- data/benchmark/results/efflorescence-m1-cruby.json +799 -0
- data/benchmark/results/efflorescence-m1-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-bulk-loop.json +820 -0
- data/benchmark/results/efflorescence-m2-i32-cruby.json +799 -0
- data/benchmark/results/efflorescence-m2-i32-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-memory.json +408 -0
- data/benchmark/results/generated_guards_exploratory_2026-11-04.json +1225 -0
- data/benchmark/results/generated_guards_profile_2026-11-04.json +592 -0
- data/benchmark/results/generated_guards_spinel_2026-11-04.json +1650 -0
- data/benchmark/results/generated_guards_validation_2026-11-04.json +256 -0
- data/benchmark/results/inlining_engines_2026-11-04.json +241 -0
- data/benchmark/results/inlining_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/inlining_spinel_2026-11-04.json +893 -0
- data/benchmark/results/operand_decode_exploratory_2026-11-04.json +1319 -0
- data/benchmark/results/operand_decode_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/operand_decode_spinel_2026-11-04.json +924 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04.json +454 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json +2679 -0
- data/benchmark/results/spinel_fetch_root_patch_2026-11-04.json +4523 -0
- data/benchmark/results/while_final_compiler_comparison_2026-11-04.json +324 -0
- data/benchmark/results/while_patched_external_2026-11-04.json +220 -0
- data/benchmark/results/while_user_unpatched_2026-11-04.json +230 -0
- data/benchmark/summarize_call_profile.py +54 -0
- data/benchmark/validate_m1_eh.rb +34 -0
- data/benchmark/validate_m2.rb +119 -0
- data/benchmark/validate_m3.rb +44 -0
- data/benchmark/validate_m4.rb +95 -0
- data/benchmark/validate_m5.rb +108 -0
- data/docs/adr/0001-efflorescence-m1-control-and-eh.md +319 -0
- data/docs/adr/0002-efflorescence-m2-memory-and-globals.md +185 -0
- data/docs/adr/0003-efflorescence-m3-host-and-indirect-calls.md +228 -0
- data/docs/adr/0004-efflorescence-m4-i64.md +202 -0
- data/docs/adr/0005-efflorescence-m5-floating-point.md +127 -0
- data/docs/adr/0006-efflorescence-m6-coverage-parity.md +101 -0
- data/docs/efflorescence-call-arities.md +115 -0
- data/docs/efflorescence-call-investigation.md +155 -0
- data/docs/efflorescence-call-transfer.md +128 -0
- data/docs/efflorescence-call-types.md +102 -0
- data/docs/efflorescence-coverage-ja.md +351 -0
- data/docs/efflorescence-generated-c-guards.md +405 -0
- data/docs/efflorescence-inlining.md +165 -0
- data/docs/efflorescence-ja.md +155 -0
- data/docs/efflorescence-m1.md +160 -0
- data/docs/efflorescence-m2.md +233 -0
- data/docs/efflorescence-m3.md +131 -0
- data/docs/efflorescence-m4.md +88 -0
- data/docs/efflorescence-m5.md +82 -0
- data/docs/efflorescence-m6.md +95 -0
- data/docs/efflorescence-operand-decoding.md +105 -0
- data/docs/efflorescence-phase2-ja.md +225 -0
- data/docs/efflorescence-phase2.md +240 -0
- data/docs/efflorescence-register-initialization.md +75 -0
- data/docs/efflorescence.md +144 -0
- data/docs/spinel-string-aset-inplace-proposal.md +200 -0
- data/lib/wardite/alu_f32.generated.rb +1 -0
- data/lib/wardite/alu_f64.generated.rb +1 -0
- data/lib/wardite/alu_i32.generated.rb +14 -9
- data/lib/wardite/alu_i64.generated.rb +18 -20
- data/lib/wardite/cli/cli.rb +61 -28
- data/lib/wardite/const.rb +1 -0
- data/lib/wardite/efflorescence/float_arithmetic.rb +216 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +257 -0
- data/lib/wardite/efflorescence/inspection.rb +165 -0
- data/lib/wardite/efflorescence/ir.rb +1151 -0
- data/lib/wardite/efflorescence/optimizer.rb +580 -0
- data/lib/wardite/efflorescence/register_validation.rb +290 -0
- data/lib/wardite/efflorescence/store_access.rb +271 -0
- data/lib/wardite/efflorescence/translator.rb +859 -0
- data/lib/wardite/efflorescence/vm.rb +1006 -0
- data/lib/wardite/efflorescence/wasi.rb +108 -0
- data/lib/wardite/efflorescence.rb +11 -0
- data/lib/wardite/errors.rb +20 -0
- data/lib/wardite/float_bits.rb +46 -0
- data/lib/wardite/instruction.rb +35 -4
- data/lib/wardite/leb128.rb +33 -12
- data/lib/wardite/load.rb +203 -138
- data/lib/wardite/value.rb +169 -175
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite/wasi/consts.rb +1 -0
- data/lib/wardite/wasm_module.rb +6 -3
- data/lib/wardite.rb +184 -70
- data/rbs_collection.lock.yaml +36 -96
- data/scripts/gen_alu.rb +66 -10
- data/sig/generated/wardite/cli/cli.rbs +8 -6
- data/sig/generated/wardite/const.rbs +2 -0
- data/sig/generated/wardite/efflorescence/float_arithmetic.rbs +65 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +99 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +64 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +881 -0
- data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
- data/sig/generated/wardite/efflorescence/register_validation.rbs +76 -0
- data/sig/generated/wardite/efflorescence/store_access.rbs +134 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +214 -0
- data/sig/generated/wardite/efflorescence/vm.rbs +179 -0
- data/sig/generated/wardite/efflorescence/wasi.rbs +47 -0
- data/sig/generated/wardite/errors.rbs +12 -0
- data/sig/generated/wardite/float_bits.rbs +30 -0
- data/sig/generated/wardite/instruction.rbs +22 -1
- data/sig/generated/wardite/leb128.rbs +3 -1
- data/sig/generated/wardite/load.rbs +29 -4
- data/sig/generated/wardite/value.rbs +70 -11
- data/sig/generated/wardite/wasi/consts.rbs +2 -0
- data/sig/generated/wardite.rbs +49 -12
- data/sig/vernier.rbs +2 -2
- data/spinel/README.md +30 -0
- data/spinel/bin/wardite.rb +6 -0
- data/spinel/spin.toml +7 -0
- metadata +126 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "json"
|
|
6
|
+
require "open3"
|
|
7
|
+
require "rbconfig"
|
|
8
|
+
require "shellwords"
|
|
9
|
+
|
|
10
|
+
Dir.chdir(File.expand_path("..", __dir__))
|
|
11
|
+
$stdout.sync = true
|
|
12
|
+
ablation = ENV["INLINE_ABLATION"] == "1"
|
|
13
|
+
arities = ENV["CALL_ARITIES"] == "1"
|
|
14
|
+
mix_only = ENV["MIX_ONLY"] == "1"
|
|
15
|
+
experiment = ENV["CALL_ARITY_EXPERIMENT"] == "1"
|
|
16
|
+
abort "Choose only one of CALL_ARITIES, INLINE_ABLATION or MIX_ONLY" if [arities, ablation, mix_only].count(true) > 1
|
|
17
|
+
abort "CALL_ARITY_EXPERIMENT requires CALL_ARITIES=1" if experiment && !arities
|
|
18
|
+
output = File.expand_path("build/benchmark/#{arities ? 'call-arities' : (ablation ? 'inlining' : 'call-types')}")
|
|
19
|
+
FileUtils.mkdir_p(output)
|
|
20
|
+
rounds = Integer(ARGV.fetch(0, "1000000"), 10)
|
|
21
|
+
seed = Integer(ARGV.fetch(1, "123"), 10)
|
|
22
|
+
runs = Integer(ENV.fetch("RUNS", "7"))
|
|
23
|
+
warmups = Integer(ENV.fetch("WARMUPS", "2"))
|
|
24
|
+
abort "invalid inputs" unless (0..0x7fffffff).cover?(rounds) && (0..0xffffffff).cover?(seed) && runs > 1 && warmups >= 0
|
|
25
|
+
exports, fixture = if arities
|
|
26
|
+
[%w[empty_loop call_zero call_one call_two call_three call_four], "benchmark/i32_call_arities.wat"]
|
|
27
|
+
elsif mix_only
|
|
28
|
+
[%w[inline_mix call_mix], "benchmark/i32_mix.wat"]
|
|
29
|
+
else
|
|
30
|
+
[%w[empty_loop call_identity call_add_one inline_mix call_mix], "benchmark/i32_calls.wat"]
|
|
31
|
+
end
|
|
32
|
+
runtimes = ENV.fetch("RUNTIMES", "Spinel").split(",").uniq
|
|
33
|
+
abort "invalid RUNTIMES" if runtimes.empty? || !(runtimes - %w[Spinel CRuby YJIT]).empty?
|
|
34
|
+
if runtimes.include?("YJIT")
|
|
35
|
+
out, status = Open3.capture2e(RbConfig.ruby, "--yjit", "-e", "abort 'YJIT unavailable' unless defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?")
|
|
36
|
+
abort out unless status.success?
|
|
37
|
+
end
|
|
38
|
+
compiler = Shellwords.split(ENV.fetch("SPINEL", "spinel"))
|
|
39
|
+
flags = Shellwords.split(ENV.fetch("SPINELFLAGS", "-O2"))
|
|
40
|
+
version, status = Open3.capture2e(*compiler, "--version")
|
|
41
|
+
abort version unless status.success?
|
|
42
|
+
baseline = nil
|
|
43
|
+
unless ablation
|
|
44
|
+
baseline, status = Open3.capture2e("git", "rev-parse", "--verify", "--end-of-options", "#{ENV.fetch("BASELINE_REF", arities ? "8eb02af" : "fa4b14e")}^{commit}")
|
|
45
|
+
abort baseline unless status.success?
|
|
46
|
+
baseline = baseline.strip
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def run!(command, log)
|
|
50
|
+
abort "Failed: #{command.inspect}; see #{log}" unless system(*command, out: log, err: [:child, :out])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def reference(name, rounds, seed)
|
|
54
|
+
increments = {"call_zero" => 7, "call_one" => 0, "call_two" => 1, "call_three" => 3, "call_four" => 6}
|
|
55
|
+
return (seed + increments.fetch(name) * rounds) % (2**32) if increments.key?(name)
|
|
56
|
+
return seed if %w[empty_loop call_identity].include?(name)
|
|
57
|
+
return (seed + rounds) % (2**32) if name == "call_add_one"
|
|
58
|
+
x = seed
|
|
59
|
+
rounds.times do
|
|
60
|
+
x ^= x / 8192
|
|
61
|
+
x = (x * 1664525 + 1013904223) % (2**32)
|
|
62
|
+
x = (x ^ (x * 128)) % (2**32)
|
|
63
|
+
end
|
|
64
|
+
x
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def worker_sample(command, expected)
|
|
68
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
69
|
+
out, err, status = Open3.capture3(*command)
|
|
70
|
+
e2e = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
71
|
+
fields = out.lines.first.to_s.strip.split(",")
|
|
72
|
+
abort "Checksum mismatch: #{command.inspect}\n#{out}#{err}" unless status.success? && fields.size == 4 && Integer(fields[3]) == expected
|
|
73
|
+
{worker_e2e: e2e, load: Float(fields[0]), translate: Float(fields[1]), execute: Float(fields[2]),
|
|
74
|
+
metrics: out.lines[1]&.strip, mir: out.lines[2]&.strip}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def cli_sample(command, expected)
|
|
78
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
79
|
+
out, err, status = Open3.capture3(*command)
|
|
80
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
81
|
+
signed = expected >= 0x80000000 ? expected - 0x100000000 : expected
|
|
82
|
+
abort "CLI checksum mismatch: #{command.inspect}\n#{out}#{err}" unless status.success? && out.empty? && err == "return value: I32(#{signed})\n"
|
|
83
|
+
elapsed
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def statistics(values)
|
|
87
|
+
mean = values.sum / values.size
|
|
88
|
+
{mean: mean, sd: Math.sqrt(values.sum { |value| (value - mean)**2 } / (values.size - 1)), min: values.min, max: values.max}
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
wasm = "#{output}/#{File.basename(fixture, '.wat')}.wasm"
|
|
92
|
+
run!(["wasm-tools", "parse", fixture, "-o", wasm], "#{output}/wat-build.log")
|
|
93
|
+
archive = "#{output}/baseline.tar"
|
|
94
|
+
run!(["git", "archive", "--output", archive, baseline, "lib", "exe", "benchmark/call_cost_worker.rb"], "#{output}/archive.log") unless ablation
|
|
95
|
+
snapshots = {}
|
|
96
|
+
(ablation ? ["current"] : %w[baseline current]).each do |variant|
|
|
97
|
+
directory = "#{output}/#{variant}"
|
|
98
|
+
FileUtils.mkdir_p(directory)
|
|
99
|
+
%w[lib exe benchmark].each { |name| FileUtils.rm_rf("#{directory}/#{name}") }
|
|
100
|
+
if variant == "baseline"
|
|
101
|
+
run!(["tar", "-xf", archive, "-C", directory], "#{output}/extract.log")
|
|
102
|
+
else
|
|
103
|
+
FileUtils.cp_r(["lib", "exe"], directory)
|
|
104
|
+
FileUtils.mkdir_p("#{directory}/benchmark")
|
|
105
|
+
FileUtils.cp("benchmark/call_cost_worker.rb", "#{directory}/benchmark")
|
|
106
|
+
if experiment
|
|
107
|
+
# Replay the rejected prototype only in the copied library, never lib/.
|
|
108
|
+
recorded = JSON.parse(File.read("benchmark/results/call_arities_spinel_2026-11-04.json"))
|
|
109
|
+
patch = "#{output}/experiment.patch"
|
|
110
|
+
File.write(patch, recorded.fetch("patches").fetch("lib/wardite/efflorescence/ir.rb"))
|
|
111
|
+
prefix = directory.delete_prefix("#{Dir.pwd}/")
|
|
112
|
+
run!(["git", "apply", "--check", "--directory=#{prefix}", patch], "#{output}/patch-check.log")
|
|
113
|
+
run!(["git", "apply", "--directory=#{prefix}", patch], "#{output}/patch.log")
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
sources = Dir["#{directory}/{lib,exe,benchmark}/**/*"].select { |path| File.file?(path) }.sort.to_h do |path|
|
|
117
|
+
[path.delete_prefix("#{directory}/"), Digest::SHA256.file(path).hexdigest]
|
|
118
|
+
end
|
|
119
|
+
fingerprint = Digest::SHA256.hexdigest(JSON.generate([compiler, version, flags, sources]))
|
|
120
|
+
manifest_path = "#{directory}/build-manifest.json"
|
|
121
|
+
manifest = File.exist?(manifest_path) ? JSON.parse(File.read(manifest_path)) : {}
|
|
122
|
+
cached = manifest["fingerprint"] == fingerprint && %w[wardite worker].all? do |name|
|
|
123
|
+
File.exist?("#{directory}/#{name}") && Digest::SHA256.file("#{directory}/#{name}").hexdigest == manifest.fetch("binaries", {})[name]
|
|
124
|
+
end
|
|
125
|
+
unless cached
|
|
126
|
+
{"wardite" => "exe/wardite", "worker" => "benchmark/call_cost_worker.rb"}.each do |binary, entry|
|
|
127
|
+
run!([*compiler, "-I#{directory}/lib", "--strict-require", *flags, "#{directory}/#{entry}", "-o", "#{directory}/#{binary}"], "#{directory}/#{binary}-build.log")
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
binaries = %w[wardite worker].to_h { |name| [name, Digest::SHA256.file("#{directory}/#{name}").hexdigest] }
|
|
131
|
+
File.write(manifest_path, JSON.pretty_generate({fingerprint: fingerprint, binaries: binaries}) + "\n")
|
|
132
|
+
snapshots[variant] = {directory: directory, source_sha256: sources, binary_sha256: binaries}
|
|
133
|
+
puts "#{cached ? "Reused verified build" : "Built"} #{variant}"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
checksums = exports.to_h { |name| [name, reference(name, rounds, seed)] }
|
|
137
|
+
variants = ablation ? %w[inline_off inline_on] : %w[baseline current]
|
|
138
|
+
rows = runtimes.flat_map do |runtime|
|
|
139
|
+
exports.flat_map do |name|
|
|
140
|
+
variants.map do |variant|
|
|
141
|
+
snapshot = snapshots.fetch(ablation ? "current" : variant)
|
|
142
|
+
directory = snapshot[:directory]
|
|
143
|
+
# Historical CALL-mechanism comparisons must keep calls in the MIR.
|
|
144
|
+
# Older snapshots predate the switch, so pass it only when supported.
|
|
145
|
+
features = File.read("#{directory}/lib/wardite/efflorescence/optimizer.rb")[/FEATURES = %i\[([^\]]+)\]/, 1].to_s.split
|
|
146
|
+
disabled = variant == "inline_off" || (!ablation && features.include?("inline")) ? "inline" : ""
|
|
147
|
+
ruby = [RbConfig.ruby, runtime == "YJIT" ? "--yjit" : "--disable-yjit", "-I#{directory}/lib"]
|
|
148
|
+
worker = runtime == "Spinel" ? ["#{directory}/worker"] : [*ruby, "#{directory}/benchmark/call_cost_worker.rb"]
|
|
149
|
+
worker += [wasm, name, rounds.to_s, seed.to_s]
|
|
150
|
+
profile = worker_sample([*worker, disabled, "metrics"], checksums.fetch(name))
|
|
151
|
+
cli = runtime == "Spinel" ? ["#{directory}/wardite"] : [*ruby, "#{directory}/exe/wardite"]
|
|
152
|
+
cli += ["--mir-disable", "inline"] unless disabled.empty?
|
|
153
|
+
cli += ["--new-engine", "--no-wasi", "--invoke", name, "--", wasm, rounds.to_s, seed.to_s]
|
|
154
|
+
# Arity mode times every CLI; historical mode times acceptance exports.
|
|
155
|
+
# All controls use the same phase worker and public unboxed boundary.
|
|
156
|
+
cli = nil unless arities || %w[inline_mix call_mix].include?(name)
|
|
157
|
+
{runtime: runtime, variant: variant, disabled: disabled, export: name, worker: worker, cli: cli,
|
|
158
|
+
metrics: profile.fetch(:metrics), mir: profile.fetch(:mir), samples: []}
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
rows.each do |row|
|
|
163
|
+
[[0, 0], [0, 123], [1, 0xffffffff], [10, 123], [1000, 0xffffffff]].each do |count, initial|
|
|
164
|
+
command = row[:worker].dup
|
|
165
|
+
command[-2] = count.to_s
|
|
166
|
+
command[-1] = initial.to_s
|
|
167
|
+
worker_sample([*command, row[:disabled]], reference(row[:export], count, initial))
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
runtimes.product(exports).each do |runtime, name|
|
|
171
|
+
before = rows.find { |row| row[:runtime] == runtime && row[:variant] == variants[0] && row[:export] == name }
|
|
172
|
+
after = rows.find { |row| row[:runtime] == runtime && row[:variant] == variants[1] && row[:export] == name }
|
|
173
|
+
if ablation && name.start_with?("call_")
|
|
174
|
+
off = before[:metrics].split.to_h { |field| key, value = field.split("="); [key, Integer(value)] }
|
|
175
|
+
on = after[:metrics].split.to_h { |field| key, value = field.split("="); [key, Integer(value)] }
|
|
176
|
+
abort "Unexpected inlining counters" unless off.fetch("function_entries") == rounds + 1 &&
|
|
177
|
+
on.fetch("function_entries") == 1 && on.fetch("frames_created") == 1 && on.fetch("dispatches") <= off.fetch("dispatches")
|
|
178
|
+
else
|
|
179
|
+
abort "MIR metrics differ" unless before[:metrics] == after[:metrics]
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
puts "All boundary and measured checksums agree with the independent reference."
|
|
183
|
+
|
|
184
|
+
(warmups + runs).times do |iteration|
|
|
185
|
+
ordered = rows.rotate(iteration * 3)
|
|
186
|
+
ordered.reverse! if iteration.odd?
|
|
187
|
+
ordered.each do |row|
|
|
188
|
+
expected = checksums.fetch(row[:export])
|
|
189
|
+
sample = worker_sample([*row[:worker], row[:disabled]], expected).reject { |key, _| [:metrics, :mir].include?(key) }
|
|
190
|
+
sample[:cli_e2e] = cli_sample(row[:cli], expected) if row[:cli]
|
|
191
|
+
row[:samples] << sample if iteration >= warmups
|
|
192
|
+
end
|
|
193
|
+
puts "Completed #{iteration < warmups ? "warmup" : "sample"} #{iteration < warmups ? iteration + 1 : iteration - warmups + 1}"
|
|
194
|
+
end
|
|
195
|
+
rows.each do |row|
|
|
196
|
+
row[:statistics_ms] = row[:samples].first.keys.to_h do |phase|
|
|
197
|
+
[phase, statistics(row[:samples].map { |sample| sample.fetch(phase) * 1000 })]
|
|
198
|
+
end
|
|
199
|
+
stat = row[:statistics_ms][:execute]
|
|
200
|
+
puts "%s/%s/%s: %.3f ± %.3f ms" % [row[:runtime], row[:export], row[:variant], stat[:mean], stat[:sd]]
|
|
201
|
+
row.delete(:worker)
|
|
202
|
+
row.delete(:cli)
|
|
203
|
+
end
|
|
204
|
+
snapshots.each_value { |snapshot| snapshot.delete(:directory) }
|
|
205
|
+
report = {comparison: ablation ? "same binary, inline off/on" : "commits", baseline_commit: baseline,
|
|
206
|
+
fixture: fixture, fixture_sha256: Digest::SHA256.file(fixture).hexdigest,
|
|
207
|
+
call_arity_experiment: experiment,
|
|
208
|
+
rounds: rounds, seed: seed, runs: runs, warmups: warmups,
|
|
209
|
+
spinel: version.strip, spinel_flags: flags, ruby: RUBY_DESCRIPTION, checksums: checksums, snapshots: snapshots, results: rows}
|
|
210
|
+
report_path = "#{output}/#{mix_only ? 'mix-results.json' : 'results.json'}"
|
|
211
|
+
File.write(report_path, JSON.pretty_generate(report) + "\n")
|
|
212
|
+
puts "Saved #{report_path}"
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Reconstruct the constant-label baseline from the current VM's Opcode comments
|
|
4
|
+
# so both variants contain exactly the same optimizations and return boundary.
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "json"
|
|
7
|
+
require "open3"
|
|
8
|
+
require "rbconfig"
|
|
9
|
+
require "shellwords"
|
|
10
|
+
require "tmpdir"
|
|
11
|
+
|
|
12
|
+
Dir.chdir(File.expand_path("..", __dir__))
|
|
13
|
+
$stdout.sync = true
|
|
14
|
+
root = Dir.pwd
|
|
15
|
+
rounds = Integer(ARGV.fetch(0, "100000"), 10)
|
|
16
|
+
seed = Integer(ARGV.fetch(1, "123"), 10)
|
|
17
|
+
runs = Integer(ENV.fetch("RUNS", "5"))
|
|
18
|
+
warmups = Integer(ENV.fetch("WARMUPS", "2"))
|
|
19
|
+
abort "invalid inputs" unless (0..0x7fffffff).cover?(rounds) && (0..0xffffffff).cover?(seed) && runs > 0 && warmups >= 0
|
|
20
|
+
compiler = Shellwords.split(ENV.fetch("SPINEL", "spinel"))
|
|
21
|
+
flags = Shellwords.split(ENV.fetch("SPINELFLAGS", "-O2"))
|
|
22
|
+
version, status = Open3.capture2e(*compiler, "--version")
|
|
23
|
+
abort version unless status.success?
|
|
24
|
+
FileUtils.mkdir_p("build/benchmark")
|
|
25
|
+
wasm = File.expand_path("build/benchmark/i32_mix.wasm")
|
|
26
|
+
abort "WAT compilation failed" unless system("wasm-tools", "parse", "benchmark/i32_mix.wat", "-o", wasm)
|
|
27
|
+
abort "CLI build failed" unless system("make", "spinel", out: "build/benchmark/dispatch-build.log", err: [:child, :out])
|
|
28
|
+
|
|
29
|
+
def compile(compiler, flags, source, library, destination, log)
|
|
30
|
+
abort "Build failed; see #{log}" unless system(*compiler, "--strict-require", "-I#{library}", *flags,
|
|
31
|
+
source, "-o", destination, out: log, err: [:child, :out])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def verify(command, expected, worker: false)
|
|
35
|
+
out, err, status = Open3.capture3(*command)
|
|
36
|
+
values = out.strip.split(",")
|
|
37
|
+
signed = expected >= 0x80000000 ? expected - 0x100000000 : expected
|
|
38
|
+
valid = if worker
|
|
39
|
+
values.size == 5 && Integer(values[3]) == expected
|
|
40
|
+
else
|
|
41
|
+
out.empty? && err == "return value: I32(#{signed})\n"
|
|
42
|
+
end
|
|
43
|
+
abort "Checksum mismatch: #{command.inspect}\n#{out}#{err}" unless status.success? && valid
|
|
44
|
+
worker ? values.first(3).map { |value| Float(value) } : []
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
checksum = seed
|
|
48
|
+
rounds.times do
|
|
49
|
+
checksum ^= checksum / 8192
|
|
50
|
+
checksum = (checksum * 1664525 + 1013904223) % (2**32)
|
|
51
|
+
checksum = (checksum ^ (checksum * 128)) % (2**32)
|
|
52
|
+
end
|
|
53
|
+
compile(compiler, flags, "benchmark/optimization_worker.rb", "lib", "build/benchmark/optimization_worker",
|
|
54
|
+
"build/benchmark/dispatch-worker-build.log")
|
|
55
|
+
|
|
56
|
+
results = []
|
|
57
|
+
Dir.mktmpdir("dispatch-constants-", "build/benchmark") do |temporary|
|
|
58
|
+
baseline = File.expand_path(temporary)
|
|
59
|
+
FileUtils.cp_r(["lib", "exe"], baseline)
|
|
60
|
+
FileUtils.mkdir_p("#{baseline}/benchmark")
|
|
61
|
+
FileUtils.cp("benchmark/optimization_worker.rb", "#{baseline}/benchmark/optimization_worker.rb")
|
|
62
|
+
vm_file = "#{baseline}/lib/wardite/efflorescence/vm.rb"
|
|
63
|
+
source = File.read(vm_file).gsub(/^([ ]*)when \d+ # (Opcode::[A-Z_0-9]+)$/) { "#{$1}when #{$2}" }
|
|
64
|
+
# Count the original labels independently to guard against a stale benchmark.
|
|
65
|
+
labels = File.read(vm_file).scan(/^\s*when \d+ # Opcode::[A-Z_0-9]+$/).size
|
|
66
|
+
abort "Expected both 23-opcode dispatches, found #{labels} labels" unless labels == 46
|
|
67
|
+
File.write(vm_file, source)
|
|
68
|
+
compile(compiler, flags, "#{baseline}/exe/wardite", "#{baseline}/lib", "#{baseline}/wardite",
|
|
69
|
+
"build/benchmark/dispatch-constant-build.log")
|
|
70
|
+
compile(compiler, flags, "#{baseline}/benchmark/optimization_worker.rb", "#{baseline}/lib", "#{baseline}/worker",
|
|
71
|
+
"build/benchmark/dispatch-constant-worker-build.log")
|
|
72
|
+
|
|
73
|
+
runtimes = {"CRuby" => [RbConfig.ruby, "--disable-yjit"], "Spinel" => []}
|
|
74
|
+
_out, yjit = Open3.capture2e(RbConfig.ruby, "--yjit", "-e", "exit(defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled? ? 0 : 1)")
|
|
75
|
+
runtimes["YJIT"] = [RbConfig.ruby, "--yjit"] if yjit.success?
|
|
76
|
+
if ENV["RUNTIMES"]
|
|
77
|
+
requested = ENV.fetch("RUNTIMES").split(",")
|
|
78
|
+
abort "Unknown runtime" if requested.empty? || !(requested - runtimes.keys).empty?
|
|
79
|
+
runtimes.select! { |name, _| requested.include?(name) }
|
|
80
|
+
end
|
|
81
|
+
matrix = []
|
|
82
|
+
runtimes.each do |name, runner|
|
|
83
|
+
%w[inline_mix call_mix].each do |export|
|
|
84
|
+
%w[constant literal].each do |style|
|
|
85
|
+
directory = style == "constant" ? baseline : root
|
|
86
|
+
if name == "Spinel"
|
|
87
|
+
cli = [style == "constant" ? "#{baseline}/wardite" : "#{root}/build/wardite"]
|
|
88
|
+
worker = [style == "constant" ? "#{baseline}/worker" : "#{root}/build/benchmark/optimization_worker"]
|
|
89
|
+
else
|
|
90
|
+
cli = runner + ["-I#{directory}/lib", "#{directory}/exe/wardite"]
|
|
91
|
+
worker = runner + ["-I#{directory}/lib", "#{directory}/benchmark/optimization_worker.rb"]
|
|
92
|
+
end
|
|
93
|
+
cli += ["--new-engine", "--no-wasi", "--invoke", export, "--", wasm, rounds.to_s, seed.to_s]
|
|
94
|
+
worker += [wasm, export, rounds.to_s, seed.to_s, ""]
|
|
95
|
+
verify(cli, checksum)
|
|
96
|
+
verify(worker, checksum, worker: true)
|
|
97
|
+
matrix << {runtime: name, export: export, style: style, cli: cli, worker: worker, samples: []}
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
puts "All #{matrix.size} CLI/worker pairs match checksum #{checksum}."
|
|
102
|
+
matrix.each_slice(2) do |pair|
|
|
103
|
+
(warmups + runs).times do |iteration|
|
|
104
|
+
# Alternate the order of paired samples to reduce ordering bias.
|
|
105
|
+
(iteration.even? ? pair : pair.reverse).each do |row|
|
|
106
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
107
|
+
verify(row[:cli], checksum)
|
|
108
|
+
e2e = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
109
|
+
phases = verify(row[:worker], checksum, worker: true)
|
|
110
|
+
row[:samples] << [e2e, *phases] if iteration >= warmups
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
pair.each do |row|
|
|
114
|
+
means = (0...4).map { |i| row[:samples].sum { |sample| sample[i] } * 1000 / runs }
|
|
115
|
+
results << {runtime: row[:runtime], export: row[:export], style: row[:style],
|
|
116
|
+
e2e_ms: means[0], load_ms: means[1], translate_ms: means[2], execute_ms: means[3], samples_seconds: row[:samples]}
|
|
117
|
+
puts "%s/%s/%s: e2e=%.2f ms execute=%.2f ms" % [row[:runtime], row[:export], row[:style], means[0], means[3]]
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
File.write("build/benchmark/dispatch.json", JSON.pretty_generate({rounds: rounds, seed: seed, checksum: checksum,
|
|
122
|
+
runs: runs, warmups: warmups, ruby: RUBY_DESCRIPTION, spinel: version.strip, spinel_flags: flags, results: results}))
|
|
123
|
+
puts "Saved build/benchmark/dispatch.json"
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "json"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "rbconfig"
|
|
7
|
+
require "shellwords"
|
|
8
|
+
|
|
9
|
+
Dir.chdir(File.expand_path("..", __dir__))
|
|
10
|
+
rounds = Integer(ARGV.fetch(0, "100000"), 10)
|
|
11
|
+
seed = Integer(ARGV.fetch(1, "123"), 10)
|
|
12
|
+
abort "rounds must be 0..2147483647; seed must be 0..4294967295" unless
|
|
13
|
+
(0..0x7fffffff).cover?(rounds) && (0..0xffffffff).cover?(seed)
|
|
14
|
+
runs = Integer(ENV.fetch("RUNS", "5"))
|
|
15
|
+
warmups = Integer(ENV.fetch("WARMUPS", "2"))
|
|
16
|
+
abort "RUNS must be positive; WARMUPS must be nonnegative" unless runs > 0 && warmups >= 0
|
|
17
|
+
FileUtils.mkdir_p("build/benchmark")
|
|
18
|
+
wasm = "build/benchmark/i32_mix.wasm"
|
|
19
|
+
abort "WAT compilation failed" unless system("wasm-tools", "parse", "benchmark/i32_mix.wat", "-o", wasm)
|
|
20
|
+
abort "Spinel CLI build failed" unless system("make", "spinel")
|
|
21
|
+
compiler = Shellwords.split(ENV.fetch("SPINEL", "spinel"))
|
|
22
|
+
flags = Shellwords.split(ENV.fetch("SPINELFLAGS", "-O2"))
|
|
23
|
+
abort "Spinel phase runner build failed" unless system(*compiler, "-I", "lib", "--strict-require", *flags,
|
|
24
|
+
"benchmark/engine_phases.rb", "-o", "build/benchmark/engine_phases")
|
|
25
|
+
|
|
26
|
+
def reference(rounds, seed)
|
|
27
|
+
x = seed % (2**32)
|
|
28
|
+
rounds.times do
|
|
29
|
+
x ^= x / (2**13)
|
|
30
|
+
x = (x * 1664525 + 1013904223) % (2**32)
|
|
31
|
+
x = (x ^ (x * (2**7))) % (2**32)
|
|
32
|
+
end
|
|
33
|
+
x
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
runtimes = {
|
|
37
|
+
"CRuby" => [RbConfig.ruby, "--disable-yjit", "-Ilib"],
|
|
38
|
+
"Spinel" => ["./build/wardite"]
|
|
39
|
+
}
|
|
40
|
+
_output, yjit = Open3.capture2e(RbConfig.ruby, "--yjit", "-e",
|
|
41
|
+
"exit(defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled? ? 0 : 1)")
|
|
42
|
+
runtimes["CRuby + YJIT"] = [RbConfig.ruby, "--yjit", "-Ilib"] if yjit.success?
|
|
43
|
+
|
|
44
|
+
def cli_command(runner, engine, export, wasm, rounds, seed)
|
|
45
|
+
command = runner.dup
|
|
46
|
+
command << "exe/wardite" unless runner.first == "./build/wardite"
|
|
47
|
+
command << "--new-engine" if engine == "efflorescence"
|
|
48
|
+
command + ["--no-wasi", "--invoke", export, "--", wasm, rounds.to_s, seed.to_s]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def checked_cli(command, checksum)
|
|
52
|
+
signed = checksum >= 0x80000000 ? checksum - 0x100000000 : checksum
|
|
53
|
+
stdout, stderr, status = Open3.capture3(*command)
|
|
54
|
+
abort "Checksum failure: #{command.inspect}: #{stdout.inspect} #{stderr.inspect}" unless
|
|
55
|
+
status.success? && stdout.empty? && stderr == "return value: I32(#{signed})\n"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def checked_phases(command, checksum)
|
|
59
|
+
stdout, stderr, status = Open3.capture3(*command)
|
|
60
|
+
fields = stdout.strip.split(",")
|
|
61
|
+
abort "Phase runner failed: #{command.inspect}: #{stdout.inspect} #{stderr.inspect}" unless
|
|
62
|
+
status.success? && fields.size == 4 && Integer(fields[3]) == checksum
|
|
63
|
+
fields.first(3).map { |value| Float(value) }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Gate ALL performance measurement on the complete acceptance matrix.
|
|
67
|
+
cases = [[0, 0], [0, 123], [1, 0], [1, 123], [10, 123], [1000, 123],
|
|
68
|
+
[1000, 0xffffffff], [100000, 123], [rounds, seed]].uniq
|
|
69
|
+
cases.each do |count, input|
|
|
70
|
+
expected = reference(count, input)
|
|
71
|
+
runtimes.each_value do |runner|
|
|
72
|
+
%w[stack efflorescence].each do |engine|
|
|
73
|
+
%w[inline_mix call_mix].each do |export|
|
|
74
|
+
checked_cli(cli_command(runner, engine, export, wasm, count, input), expected)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
phase_runners = runtimes.transform_values do |runner|
|
|
80
|
+
runner.first == "./build/wardite" ? ["./build/benchmark/engine_phases"] : runner + ["benchmark/engine_phases.rb"]
|
|
81
|
+
end
|
|
82
|
+
phase_runners.each_value do |runner|
|
|
83
|
+
%w[stack efflorescence].each do |engine|
|
|
84
|
+
%w[inline_mix call_mix].each do |export|
|
|
85
|
+
checked_phases(runner + [wasm, engine, export, rounds.to_s, seed.to_s], reference(rounds, seed))
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
puts "All #{cases.size} input cases match the independent reference on both engines and all runtimes."
|
|
90
|
+
|
|
91
|
+
expected = reference(rounds, seed)
|
|
92
|
+
results = []
|
|
93
|
+
%w[inline_mix call_mix].each do |export|
|
|
94
|
+
runtimes.each do |name, runner|
|
|
95
|
+
%w[stack efflorescence].each do |engine|
|
|
96
|
+
command = cli_command(runner, engine, export, wasm, rounds, seed)
|
|
97
|
+
phase_runner = phase_runners.fetch(name)
|
|
98
|
+
phase_command = phase_runner + [wasm, engine, export, rounds.to_s, seed.to_s]
|
|
99
|
+
samples = []
|
|
100
|
+
(warmups + runs).times do |iteration|
|
|
101
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
102
|
+
checked_cli(command, expected)
|
|
103
|
+
e2e = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
104
|
+
phases = checked_phases(phase_command, expected)
|
|
105
|
+
samples << [e2e, *phases] if iteration >= warmups
|
|
106
|
+
end
|
|
107
|
+
means = (0...4).map { |i| samples.sum { |sample| sample[i] } / runs }
|
|
108
|
+
row = {runtime: name, engine: engine, export: export, checksum: expected,
|
|
109
|
+
e2e_ms: means[0] * 1000, load_ms: means[1] * 1000,
|
|
110
|
+
translate_ms: means[2] * 1000, execute_ms: means[3] * 1000, samples_seconds: samples}
|
|
111
|
+
results << row
|
|
112
|
+
puts "%s / %s / %s: e2e %.2f ms; load %.3f ms; MIR %.3f ms; execute %.2f ms" %
|
|
113
|
+
[name, engine, export, row[:e2e_ms], row[:load_ms], row[:translate_ms], row[:execute_ms]]
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
File.write("build/benchmark/engines.json", JSON.pretty_generate({rounds: rounds, seed: seed,
|
|
118
|
+
runs: runs, warmups: warmups, ruby: RUBY_DESCRIPTION, results: results}))
|
|
119
|
+
puts "Saved build/benchmark/engines.json (rounds=#{rounds}, seed=#{seed}, checksum=#{expected})."
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "json"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "rbconfig"
|
|
7
|
+
require "shellwords"
|
|
8
|
+
require_relative "../lib/wardite"
|
|
9
|
+
|
|
10
|
+
Dir.chdir(File.expand_path("..", __dir__))
|
|
11
|
+
$stdout.sync = true
|
|
12
|
+
rounds = Integer(ARGV.fetch(0, "100000"), 10)
|
|
13
|
+
seed = Integer(ARGV.fetch(1, "123"), 10)
|
|
14
|
+
abort "invalid rounds or seed" unless (0..0x7fffffff).cover?(rounds) && (0..0xffffffff).cover?(seed)
|
|
15
|
+
runs = Integer(ENV.fetch("RUNS", "5"))
|
|
16
|
+
warmups = Integer(ENV.fetch("WARMUPS", "2"))
|
|
17
|
+
abort "invalid sample counts" unless runs > 0 && warmups >= 0
|
|
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", out: "build/benchmark/phase2-build.log", err: [:child, :out])
|
|
22
|
+
compiler = Shellwords.split(ENV.fetch("SPINEL", "spinel"))
|
|
23
|
+
flags = Shellwords.split(ENV.fetch("SPINELFLAGS", "-O2"))
|
|
24
|
+
spinel_version, version_status = Open3.capture2e(*compiler, "--version")
|
|
25
|
+
abort "Cannot identify Spinel" unless version_status.success?
|
|
26
|
+
abort "Worker build failed" unless system(*compiler, "-I", "lib", "--strict-require", *flags,
|
|
27
|
+
"benchmark/optimization_worker.rb", "-o", "build/benchmark/optimization_worker",
|
|
28
|
+
out: "build/benchmark/phase2-worker-build.log", err: [:child, :out])
|
|
29
|
+
|
|
30
|
+
def reference(rounds, seed)
|
|
31
|
+
x = seed % (2**32)
|
|
32
|
+
rounds.times do
|
|
33
|
+
x ^= x / 8192
|
|
34
|
+
x = (x * 1664525 + 1013904223) % (2**32)
|
|
35
|
+
x = (x ^ (x * 128)) % (2**32)
|
|
36
|
+
end
|
|
37
|
+
x
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
variants = {"unoptimized" => [:all], "optimized" => []}
|
|
41
|
+
if ENV["ABLATIONS"] == "1"
|
|
42
|
+
Wardite::Efflorescence::Configuration::FEATURES.each { |feature| variants["no-#{feature}"] = [feature] }
|
|
43
|
+
end
|
|
44
|
+
phase1 = ENV["PHASE1_ROOT"]
|
|
45
|
+
variants["phase1"] = [] if phase1
|
|
46
|
+
runtimes = {"CRuby" => [RbConfig.ruby, "--disable-yjit"], "Spinel" => []}
|
|
47
|
+
_output, yjit = Open3.capture2e(RbConfig.ruby, "--yjit", "-e",
|
|
48
|
+
"exit(defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled? ? 0 : 1)")
|
|
49
|
+
runtimes["YJIT"] = [RbConfig.ruby, "--yjit"] if yjit.success?
|
|
50
|
+
|
|
51
|
+
def commands(name, runner, variant, disabled, phase1, wasm, export, rounds, seed)
|
|
52
|
+
if variant == "phase1"
|
|
53
|
+
if name == "Spinel"
|
|
54
|
+
cli = [ENV.fetch("PHASE1_BIN", "build/benchmark/phase1-wardite")]
|
|
55
|
+
worker = [ENV.fetch("PHASE1_WORKER", "build/benchmark/phase1-engine-phases")]
|
|
56
|
+
else
|
|
57
|
+
cli = runner + ["-I#{phase1}/lib", "#{phase1}/exe/wardite"]
|
|
58
|
+
worker = runner + ["-I#{phase1}/lib", "#{phase1}/benchmark/engine_phases.rb"]
|
|
59
|
+
end
|
|
60
|
+
worker += [wasm, "efflorescence", export, rounds.to_s, seed.to_s]
|
|
61
|
+
else
|
|
62
|
+
cli = name == "Spinel" ? ["./build/wardite"] : runner + ["-Ilib", "exe/wardite"]
|
|
63
|
+
worker = name == "Spinel" ? ["./build/benchmark/optimization_worker"] : runner + ["-Ilib", "benchmark/optimization_worker.rb"]
|
|
64
|
+
worker += [wasm, export, rounds.to_s, seed.to_s, disabled.join(",")]
|
|
65
|
+
disabled.each { |feature| cli += ["--mir-disable", feature.to_s] }
|
|
66
|
+
end
|
|
67
|
+
[cli + ["--new-engine", "--no-wasi", "--invoke", export, "--", wasm, rounds.to_s, seed.to_s], worker]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def checked_cli(command, checksum)
|
|
71
|
+
signed = checksum >= 0x80000000 ? checksum - 0x100000000 : checksum
|
|
72
|
+
out, err, status = Open3.capture3(*command)
|
|
73
|
+
abort "CLI checksum mismatch: #{command.inspect}\n#{out}#{err}" unless
|
|
74
|
+
status.success? && out.empty? && err == "return value: I32(#{signed})\n"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def checked_worker(command, checksum)
|
|
78
|
+
out, err, status = Open3.capture3(*command)
|
|
79
|
+
values = out.strip.split(",")
|
|
80
|
+
abort "Worker checksum mismatch: #{command.inspect}\n#{out}#{err}" unless
|
|
81
|
+
status.success? && [4, 5].include?(values.size) && Integer(values[3]) == checksum
|
|
82
|
+
[*values.first(3).map { |value| Float(value) }, values[4] ? Integer(values[4]) : nil]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Gate every measured variant/runtime, including the independent Phase 1 build.
|
|
86
|
+
checksum = reference(rounds, seed)
|
|
87
|
+
matrix = []
|
|
88
|
+
runtimes.each do |name, runner|
|
|
89
|
+
variants.each do |variant, disabled|
|
|
90
|
+
%w[inline_mix call_mix].each do |export|
|
|
91
|
+
cli, worker = commands(name, runner, variant, disabled, phase1, wasm, export, rounds, seed)
|
|
92
|
+
checked_cli(cli, checksum)
|
|
93
|
+
checked_worker(worker, checksum)
|
|
94
|
+
matrix << [name, variant, disabled, export, cli, worker]
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
puts "All #{matrix.size} CLI/worker pairs agree with reference checksum #{checksum}."
|
|
99
|
+
|
|
100
|
+
# Detailed counters run separately and are never enabled in timed processes.
|
|
101
|
+
profiles = {}
|
|
102
|
+
bytes = File.binread(wasm)
|
|
103
|
+
variants.each do |variant, disabled|
|
|
104
|
+
next if variant == "phase1"
|
|
105
|
+
%w[inline_mix call_mix].each do |export|
|
|
106
|
+
vm = Wardite::BinaryLoader.load_from_buffer(StringIO.new(bytes), enable_wasi: false,
|
|
107
|
+
engine: :efflorescence, disabled_optimizations: disabled, mir_profile: true).runtime
|
|
108
|
+
abort "Profile checksum mismatch" unless vm.call_unboxed(export, [rounds, seed]) == checksum
|
|
109
|
+
inspection = Wardite::Efflorescence::Inspection.new
|
|
110
|
+
profiles["#{variant}/#{export}"] = {semantic: inspection.statistics(vm.semantic_ir),
|
|
111
|
+
optimized: inspection.statistics(vm.optimized_ir), dispatches: vm.metrics.dispatches,
|
|
112
|
+
copies: vm.metrics.copies, reads: vm.metrics.register_reads, writes: vm.metrics.register_writes,
|
|
113
|
+
frames: vm.metrics.frames_created, opcode_counts: vm.metrics.opcode_counts}
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
results = []
|
|
118
|
+
matrix.each do |name, variant, disabled, export, cli, worker|
|
|
119
|
+
samples = []
|
|
120
|
+
(warmups + runs).times do |iteration|
|
|
121
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
122
|
+
checked_cli(cli, checksum)
|
|
123
|
+
e2e = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
124
|
+
phases = checked_worker(worker, checksum)
|
|
125
|
+
samples << [e2e, *phases] if iteration >= warmups
|
|
126
|
+
end
|
|
127
|
+
means = (0...4).map { |i| samples.sum { |sample| sample[i] } * 1000 / runs }
|
|
128
|
+
allocations = name == "Spinel" || variant == "phase1" ? nil : samples.sum { |sample| sample[4] } / runs.to_f
|
|
129
|
+
results << {runtime: name, variant: variant, disabled: disabled, export: export,
|
|
130
|
+
e2e_ms: means[0], load_ms: means[1], translate_ms: means[2], execute_ms: means[3],
|
|
131
|
+
allocations: allocations, samples_seconds: samples}
|
|
132
|
+
puts "%s/%s/%s: e2e=%.2f ms load=%.3f ms MIR=%.3f ms execute=%.2f ms allocations=%s" %
|
|
133
|
+
[name, variant, export, *means, allocations || "n/a"]
|
|
134
|
+
end
|
|
135
|
+
document = {rounds: rounds, seed: seed, checksum: checksum, runs: runs, warmups: warmups,
|
|
136
|
+
ruby: RUBY_DESCRIPTION, spinel: spinel_version.strip, spinel_flags: flags,
|
|
137
|
+
results: results, profiles: profiles}
|
|
138
|
+
File.write("build/benchmark/optimizations.json", JSON.pretty_generate(document))
|
|
139
|
+
puts "Saved build/benchmark/optimizations.json"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# Compiled unchanged by Spinel. Print seconds for loading, MIR translation and
|
|
5
|
+
# execution, followed by the unsigned checksum. The fixture has no start section.
|
|
6
|
+
require "wardite"
|
|
7
|
+
|
|
8
|
+
wasm = ARGV.fetch(0)
|
|
9
|
+
engine = ARGV.fetch(1)
|
|
10
|
+
export = ARGV.fetch(2)
|
|
11
|
+
rounds = ARGV.fetch(3).to_i
|
|
12
|
+
seed = ARGV.fetch(4).to_i
|
|
13
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
14
|
+
instance = File.open(wasm, "rb") do |file|
|
|
15
|
+
Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false)
|
|
16
|
+
end
|
|
17
|
+
loaded = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
18
|
+
if engine == "efflorescence"
|
|
19
|
+
mir_vm = Wardite::Efflorescence::VM.new(instance)
|
|
20
|
+
translated = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
21
|
+
result = mir_vm.call(export, [rounds, seed]) || raise("missing checksum")
|
|
22
|
+
else
|
|
23
|
+
# Construct each engine explicitly after shared loading, keeping receiver
|
|
24
|
+
# types concrete in Spinel. The fixture has no start function to invoke twice.
|
|
25
|
+
stack_vm = Wardite::Runtime.new(instance)
|
|
26
|
+
translated = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
27
|
+
result = stack_vm.call(export, [rounds, seed]) || raise("missing checksum")
|
|
28
|
+
end
|
|
29
|
+
finished = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
30
|
+
puts "#{loaded - started},#{translated - loaded},#{finished - translated},#{result.value}"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# New VM / Spinel comparison
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
These eight summary rows use the user's final results, with five runs per row.
|
|
6
|
+
Efflorescence / Spinel averaged **6.6 ms** for both exports; Wasmtime averaged
|
|
7
|
+
6.8 ms for `inline_mix` and 6.9 ms for `call_mix`. Their ranges overlap, so the
|
|
8
|
+
figure does not establish a statistically significant lead.
|
|
9
|
+
|
|
10
|
+
Efflorescence uses while-based flat dispatch and Spinel's local fetch-root-elision
|
|
11
|
+
patch (`6f1a2c259`). The compiler patch is recorded separately from the Wardite
|
|
12
|
+
implementation; see the [investigation](../../docs/efflorescence-generated-c-guards.md).
|
|
13
|
+
|
|
14
|
+
The body shows mean ± standard deviation, the central line shows the mean,
|
|
15
|
+
and whiskers show the observed minimum and maximum. Both panels use the same
|
|
16
|
+
millisecond scale. Mean ± standard deviation can extend beyond the observed
|
|
17
|
+
range; it is preserved without clipping. No quartiles or per-run values are
|
|
18
|
+
inferred from the summaries.
|
|
19
|
+
|
|
20
|
+
These are **whole CLI process times**, including startup, module loading and
|
|
21
|
+
execution. Wasmtime also compiles the module in each process, with its
|
|
22
|
+
compiled-module cache disabled. They are not execution-loop-only timings.
|
|
23
|
+
|
|
24
|
+
The supplied, one-decimal-millisecond summaries are in
|
|
25
|
+
`spinel_new_vm_summary.json` and `.csv`. They preserve the five-run summary
|
|
26
|
+
supplied in the conversation; the mutable `build/benchmark/results.json` is not
|
|
27
|
+
used when regenerating this figure. No per-run observations are inferred.
|
|
28
|
+
PNG and SVG exports are included. To regenerate on macOS with Matplotlib and the
|
|
29
|
+
Hiragino Kaku Gothic W3 system font installed:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
python3 plot_spinel_comparison.py
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Run from this directory, or pass the script's path from the repository root.
|