wardite 1.3.0 → 1.3.1
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/README.md +16 -5
- data/benchmark/results/spinel-072516af1.csv +149 -0
- data/docs/efflorescence-mir-generation-performance.md +58 -0
- data/docs/efflorescence-spinel-linear-memory.md +2 -2
- data/lib/wardite/efflorescence/translator.rb +93 -7
- data/lib/wardite/version.rb +1 -1
- data/scripts/build_spinel_zig.rb +29 -17
- data/sig/generated/wardite/efflorescence/translator.rbs +18 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aba4ded539535f71f0181c13b608e48d5952e91eabff3b96459469dd80abb17c
|
|
4
|
+
data.tar.gz: 537ae2b488ebf860a4deb17a2fcfc0f10f419d388dd098402f18302a9aadcefc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e736f83dd262973f30579ab34885da0155f56cb384eae169ceabfe81d6a38b71006d2e68edcefbab11f7459d4ba9b8b2b4a3166c814384ca81dbb18b04a330ad
|
|
7
|
+
data.tar.gz: 3780db1f1b47cf7dd8ea1c2649721c7026c04c546027ecba0ce8c2ae051c15e73a819498d5a673b38145b7ed5cdd93c5978b90b5467cfd0a3953b888123e0386
|
data/README.md
CHANGED
|
@@ -89,6 +89,14 @@ the Wasm, links imports, and initializes a fresh instance. `--mir-dump` and
|
|
|
89
89
|
`--mir-profile` build MIR normally. Ruby callers can pass `mir_cache: dir`.
|
|
90
90
|
CRuby and Spinel use different cache keys.
|
|
91
91
|
|
|
92
|
+
On a cold load, native Spinel translates modules with at least 32 defined
|
|
93
|
+
functions using up to eight workers, including the calling thread. Smaller
|
|
94
|
+
modules and CRuby use one worker by default. Set `WARDITE_MIR_WORKERS=1`
|
|
95
|
+
to force serial translation, or choose 2–8 to request parallel translation
|
|
96
|
+
even for a small module. `SPINEL_WORKERS` controls the underlying Spinel
|
|
97
|
+
scheduler and also sets the default MIR worker count (up to eight).
|
|
98
|
+
`WARDITE_TRACE=1` reports semantic MIR translation time on a cache miss.
|
|
99
|
+
|
|
92
100
|
The default `--mir-cache-verify checksum` checks the payload size and samples
|
|
93
101
|
blocks. Use `--mir-cache-verify sha256` or Ruby's `mir_cache_verify: :sha256`
|
|
94
102
|
to check the whole payload. Both modes use the same cache file. By default,
|
|
@@ -170,12 +178,12 @@ CRuby build. Ruby's dynamic export helpers (`instance.add(...)` and
|
|
|
170
178
|
The build leaves inline RBS and Spinel's default integer overflow checks enabled.
|
|
171
179
|
Wasm integer operations bound their intermediate values, so
|
|
172
180
|
`--int-overflow=promote` is not required.
|
|
173
|
-
CI
|
|
174
|
-
required `IO::Buffer` changes.
|
|
181
|
+
CI and release builds use Spinel commit `072516af1`, which includes the
|
|
182
|
+
required `IO::Buffer` changes and reduces GC root lookups in threaded builds.
|
|
175
183
|
See the [build instructions and host memory API](docs/efflorescence-spinel-linear-memory.md).
|
|
176
184
|
Override `SPINEL`, `SPINELFLAGS`, `BUILD_DIR`, or `RUBY` when needed.
|
|
177
185
|
|
|
178
|
-
####
|
|
186
|
+
#### Build release executables on macOS
|
|
179
187
|
|
|
180
188
|
With Zig 0.17.1, Ruby, and the Xcode Command Line Tools installed, run:
|
|
181
189
|
|
|
@@ -184,8 +192,11 @@ make spinel-zig
|
|
|
184
192
|
```
|
|
185
193
|
|
|
186
194
|
The first build downloads and builds the same Spinel revision used in CI.
|
|
187
|
-
It builds the Spinel runtime and native StringIO code for each target
|
|
188
|
-
|
|
195
|
+
It builds the Spinel runtime and native StringIO code for each target.
|
|
196
|
+
On a local Apple Silicon Mac, the macOS arm64 executable is compiled and
|
|
197
|
+
linked with Apple Clang. To build just that executable without installing Zig,
|
|
198
|
+
run `make spinel-zig ZIG_TARGETS=aarch64-macos`. Linux targets use Zig.
|
|
199
|
+
On Intel Macs and in CI (when `CI` or `GITHUB_ACTIONS` is set), all targets use Zig.
|
|
189
200
|
|
|
190
201
|
| Target | Executable |
|
|
191
202
|
| --- | --- |
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
series,workload,mir_workers,round,position,spinel,wall_ms,module_load_ms,semantic_mir_ms
|
|
2
|
+
measurements,base64_encode,8,1,1,072516af1,515.7730,12.9039,
|
|
3
|
+
measurements,base64_encode,8,1,2,a2aa05227,556.1760,11.8799,
|
|
4
|
+
measurements,base64_encode,8,2,1,a2aa05227,557.7374,12.6789,
|
|
5
|
+
measurements,base64_encode,8,2,2,072516af1,515.2720,12.8329,
|
|
6
|
+
measurements,base64_encode,8,3,1,072516af1,514.7977,13.4690,
|
|
7
|
+
measurements,base64_encode,8,3,2,a2aa05227,562.8102,12.1920,
|
|
8
|
+
measurements,base64_encode,8,4,1,a2aa05227,556.4288,12.6119,
|
|
9
|
+
measurements,base64_encode,8,4,2,072516af1,518.0548,12.8949,
|
|
10
|
+
measurements,base64_encode,8,5,1,072516af1,517.2280,13.0160,
|
|
11
|
+
measurements,base64_encode,8,5,2,a2aa05227,555.1589,11.8351,
|
|
12
|
+
measurements,base64_encode,8,6,1,072516af1,520.2749,13.3600,
|
|
13
|
+
measurements,base64_encode,8,6,2,a2aa05227,560.6364,12.4788,
|
|
14
|
+
measurements,base64_encode,8,7,1,072516af1,515.9697,12.5692,
|
|
15
|
+
measurements,base64_encode,8,7,2,a2aa05227,558.7482,12.6290,
|
|
16
|
+
measurements,base64_encode,8,8,1,a2aa05227,557.7654,11.8520,
|
|
17
|
+
measurements,base64_encode,8,8,2,072516af1,514.5605,12.9120,
|
|
18
|
+
measurements,base64_encode,8,9,1,a2aa05227,556.7275,11.9998,
|
|
19
|
+
measurements,base64_encode,8,9,2,072516af1,513.5552,12.2981,
|
|
20
|
+
measurements,base64_encode,8,10,1,072516af1,519.3985,13.7470,
|
|
21
|
+
measurements,base64_encode,8,10,2,a2aa05227,556.8065,11.9381,
|
|
22
|
+
measurements,base64_encode,8,11,1,072516af1,518.1883,13.0858,
|
|
23
|
+
measurements,base64_encode,8,11,2,a2aa05227,553.9027,11.7872,
|
|
24
|
+
measurements,base64_encode,8,12,1,a2aa05227,559.3246,11.4069,
|
|
25
|
+
measurements,base64_encode,8,12,2,072516af1,517.7298,13.4583,
|
|
26
|
+
measurements,base64_encode,8,13,1,a2aa05227,561.2420,11.8082,
|
|
27
|
+
measurements,base64_encode,8,13,2,072516af1,517.0349,12.3420,
|
|
28
|
+
measurements,base64_encode,8,14,1,a2aa05227,554.3150,12.4421,
|
|
29
|
+
measurements,base64_encode,8,14,2,072516af1,514.4441,12.9621,
|
|
30
|
+
measurements,base64_encode,8,15,1,a2aa05227,556.3150,12.4378,
|
|
31
|
+
measurements,base64_encode,8,15,2,072516af1,513.9378,12.7800,
|
|
32
|
+
measurements,base64_encode,8,16,1,072516af1,513.8093,12.4671,
|
|
33
|
+
measurements,base64_encode,8,16,2,a2aa05227,557.8692,12.1140,
|
|
34
|
+
measurements,base64_decode,8,1,1,a2aa05227,426.6628,12.5911,
|
|
35
|
+
measurements,base64_decode,8,1,2,072516af1,408.1138,12.4581,
|
|
36
|
+
measurements,base64_decode,8,2,1,072516af1,409.8258,13.2408,
|
|
37
|
+
measurements,base64_decode,8,2,2,a2aa05227,426.0427,11.9927,
|
|
38
|
+
measurements,base64_decode,8,3,1,a2aa05227,426.1940,11.9429,
|
|
39
|
+
measurements,base64_decode,8,3,2,072516af1,409.1179,13.0141,
|
|
40
|
+
measurements,base64_decode,8,4,1,072516af1,408.8402,12.8779,
|
|
41
|
+
measurements,base64_decode,8,4,2,a2aa05227,428.5685,12.4323,
|
|
42
|
+
measurements,base64_decode,8,5,1,072516af1,409.7925,13.1991,
|
|
43
|
+
measurements,base64_decode,8,5,2,a2aa05227,428.5801,12.7790,
|
|
44
|
+
measurements,base64_decode,8,6,1,a2aa05227,426.3628,12.0380,
|
|
45
|
+
measurements,base64_decode,8,6,2,072516af1,408.5974,12.0051,
|
|
46
|
+
measurements,base64_decode,8,7,1,a2aa05227,427.7934,12.4259,
|
|
47
|
+
measurements,base64_decode,8,7,2,072516af1,409.1927,12.2960,
|
|
48
|
+
measurements,base64_decode,8,8,1,a2aa05227,428.3711,12.1150,
|
|
49
|
+
measurements,base64_decode,8,8,2,072516af1,409.3650,12.3012,
|
|
50
|
+
measurements,base64_decode,8,9,1,a2aa05227,428.3757,12.3250,
|
|
51
|
+
measurements,base64_decode,8,9,2,072516af1,410.4165,13.5150,
|
|
52
|
+
measurements,base64_decode,8,10,1,072516af1,410.8411,13.2132,
|
|
53
|
+
measurements,base64_decode,8,10,2,a2aa05227,426.7524,11.7781,
|
|
54
|
+
measurements,base64_decode,8,11,1,a2aa05227,425.8511,11.7030,
|
|
55
|
+
measurements,base64_decode,8,11,2,072516af1,412.0885,13.0661,
|
|
56
|
+
measurements,base64_decode,8,12,1,072516af1,412.6717,13.8350,
|
|
57
|
+
measurements,base64_decode,8,12,2,a2aa05227,427.9007,12.0530,
|
|
58
|
+
measurements,base64_decode,8,13,1,072516af1,408.4713,12.3210,
|
|
59
|
+
measurements,base64_decode,8,13,2,a2aa05227,427.0406,12.0702,
|
|
60
|
+
measurements,base64_decode,8,14,1,072516af1,410.4805,12.9559,
|
|
61
|
+
measurements,base64_decode,8,14,2,a2aa05227,428.4469,13.0801,
|
|
62
|
+
measurements,base64_decode,8,15,1,a2aa05227,428.5939,11.9770,
|
|
63
|
+
measurements,base64_decode,8,15,2,072516af1,412.4998,13.0317,
|
|
64
|
+
measurements,base64_decode,8,16,1,072516af1,409.7953,13.0520,
|
|
65
|
+
measurements,base64_decode,8,16,2,a2aa05227,428.7790,12.6159,
|
|
66
|
+
measurements,png_grayscale,8,1,1,a2aa05227,350.8128,23.6020,
|
|
67
|
+
measurements,png_grayscale,8,1,2,072516af1,328.8251,24.2560,
|
|
68
|
+
measurements,png_grayscale,8,2,1,072516af1,329.6681,25.6581,
|
|
69
|
+
measurements,png_grayscale,8,2,2,a2aa05227,351.0297,24.2629,
|
|
70
|
+
measurements,png_grayscale,8,3,1,a2aa05227,349.5068,23.1290,
|
|
71
|
+
measurements,png_grayscale,8,3,2,072516af1,329.2859,25.3632,
|
|
72
|
+
measurements,png_grayscale,8,4,1,072516af1,328.9210,24.1213,
|
|
73
|
+
measurements,png_grayscale,8,4,2,a2aa05227,349.8955,23.7677,
|
|
74
|
+
measurements,png_grayscale,8,5,1,072516af1,328.2483,24.0190,
|
|
75
|
+
measurements,png_grayscale,8,5,2,a2aa05227,350.6385,23.6883,
|
|
76
|
+
measurements,png_grayscale,8,6,1,a2aa05227,349.6990,23.0241,
|
|
77
|
+
measurements,png_grayscale,8,6,2,072516af1,330.2580,25.3632,
|
|
78
|
+
measurements,png_grayscale,8,7,1,072516af1,329.7139,25.0449,
|
|
79
|
+
measurements,png_grayscale,8,7,2,a2aa05227,349.2335,23.2668,
|
|
80
|
+
measurements,png_grayscale,8,8,1,072516af1,330.5018,25.7049,
|
|
81
|
+
measurements,png_grayscale,8,8,2,a2aa05227,350.2849,23.8609,
|
|
82
|
+
measurements,png_grayscale,8,9,1,072516af1,327.0479,23.1769,
|
|
83
|
+
measurements,png_grayscale,8,9,2,a2aa05227,348.6781,23.7041,
|
|
84
|
+
measurements,png_grayscale,8,10,1,072516af1,327.9299,23.8221,
|
|
85
|
+
measurements,png_grayscale,8,10,2,a2aa05227,350.3599,23.9060,
|
|
86
|
+
measurements,png_grayscale,8,11,1,a2aa05227,351.5582,23.6750,
|
|
87
|
+
measurements,png_grayscale,8,11,2,072516af1,329.1944,25.3491,
|
|
88
|
+
measurements,png_grayscale,8,12,1,a2aa05227,349.2948,23.4871,
|
|
89
|
+
measurements,png_grayscale,8,12,2,072516af1,331.8093,25.6298,
|
|
90
|
+
measurements,png_grayscale,8,13,1,a2aa05227,352.5463,26.0990,
|
|
91
|
+
measurements,png_grayscale,8,13,2,072516af1,328.9945,24.1401,
|
|
92
|
+
measurements,png_grayscale,8,14,1,a2aa05227,352.1057,25.8169,
|
|
93
|
+
measurements,png_grayscale,8,14,2,072516af1,331.8624,26.4199,
|
|
94
|
+
measurements,png_grayscale,8,15,1,a2aa05227,351.8631,24.5841,
|
|
95
|
+
measurements,png_grayscale,8,15,2,072516af1,331.3176,25.4190,
|
|
96
|
+
measurements,png_grayscale,8,16,1,072516af1,329.9637,24.5762,
|
|
97
|
+
measurements,png_grayscale,8,16,2,a2aa05227,349.4674,23.3128,
|
|
98
|
+
measurements,ruby_cold_start,8,1,1,a2aa05227,2873.7883,1769.8972,
|
|
99
|
+
measurements,ruby_cold_start,8,1,2,072516af1,3348.9351,2206.4819,
|
|
100
|
+
measurements,ruby_cold_start,8,2,1,a2aa05227,2950.2221,1812.4542,
|
|
101
|
+
measurements,ruby_cold_start,8,2,2,072516af1,3123.9456,2105.8469,
|
|
102
|
+
measurements,ruby_cold_start,8,3,1,072516af1,2938.9900,1917.3672,
|
|
103
|
+
measurements,ruby_cold_start,8,3,2,a2aa05227,2837.4564,1793.9579,
|
|
104
|
+
measurements,ruby_cold_start,8,4,1,a2aa05227,2992.8595,1954.9782,
|
|
105
|
+
measurements,ruby_cold_start,8,4,2,072516af1,3104.2802,2076.6938,
|
|
106
|
+
measurements,ruby_cold_start,8,5,1,072516af1,3049.3553,2037.4899,
|
|
107
|
+
measurements,ruby_cold_start,8,5,2,a2aa05227,2804.8059,1784.5833,
|
|
108
|
+
measurements,ruby_cold_start,8,6,1,a2aa05227,2772.6142,1767.4992,
|
|
109
|
+
measurements,ruby_cold_start,8,6,2,072516af1,3349.5743,1981.8130,
|
|
110
|
+
measurements,ruby_cold_start,8,7,1,072516af1,3058.8452,2041.6319,
|
|
111
|
+
measurements,ruby_cold_start,8,7,2,a2aa05227,2932.6667,1870.0480,
|
|
112
|
+
measurements,ruby_cold_start,8,8,1,072516af1,3141.4901,2046.9770,
|
|
113
|
+
measurements,ruby_cold_start,8,8,2,a2aa05227,2896.7467,1868.8231,
|
|
114
|
+
measurements,ruby_cold_start,8,9,1,072516af1,3014.1386,1995.4951,
|
|
115
|
+
measurements,ruby_cold_start,8,9,2,a2aa05227,2896.2967,1833.4420,
|
|
116
|
+
measurements,ruby_cold_start,8,10,1,a2aa05227,2762.4731,1744.0801,
|
|
117
|
+
measurements,ruby_cold_start,8,10,2,072516af1,2952.4577,1938.1797,
|
|
118
|
+
startup,ruby_cold_start,1,1,1,a2aa05227,4963.4360,3933.2130,2826.1330
|
|
119
|
+
startup,ruby_cold_start,1,1,2,072516af1,4729.5864,3664.0468,2326.3270
|
|
120
|
+
startup,ruby_cold_start,8,1,3,072516af1,3247.9754,2195.5359,639.6860
|
|
121
|
+
startup,ruby_cold_start,8,1,4,a2aa05227,2637.7935,1662.7889,604.1750
|
|
122
|
+
startup,ruby_cold_start,1,2,1,072516af1,8174.3613,6336.6570,4076.2740
|
|
123
|
+
startup,ruby_cold_start,8,2,2,a2aa05227,2985.9660,1945.1962,738.6710
|
|
124
|
+
startup,ruby_cold_start,1,2,3,a2aa05227,4929.9293,3949.7728,2779.0790
|
|
125
|
+
startup,ruby_cold_start,8,2,4,072516af1,2691.3229,1733.2399,526.1180
|
|
126
|
+
startup,ruby_cold_start,8,3,1,a2aa05227,2694.7594,1678.3192,709.8630
|
|
127
|
+
startup,ruby_cold_start,8,3,2,072516af1,2593.6477,1673.7609,521.7770
|
|
128
|
+
startup,ruby_cold_start,1,3,3,072516af1,4113.5821,3206.3351,2027.9640
|
|
129
|
+
startup,ruby_cold_start,1,3,4,a2aa05227,4082.0748,3179.1618,2237.9080
|
|
130
|
+
startup,ruby_cold_start,8,4,1,072516af1,2507.1788,1586.1290,538.4840
|
|
131
|
+
startup,ruby_cold_start,1,4,2,a2aa05227,4346.6829,3351.0721,2434.5130
|
|
132
|
+
startup,ruby_cold_start,8,4,3,a2aa05227,2346.4381,1444.1340,536.6670
|
|
133
|
+
startup,ruby_cold_start,1,4,4,072516af1,3914.0144,3009.9020,1921.0470
|
|
134
|
+
startup,ruby_cold_start,1,5,1,a2aa05227,4439.1288,3410.0459,2489.9250
|
|
135
|
+
startup,ruby_cold_start,1,5,2,072516af1,4420.3537,3427.2470,2165.7060
|
|
136
|
+
startup,ruby_cold_start,8,5,3,072516af1,2830.3141,1880.9161,563.7140
|
|
137
|
+
startup,ruby_cold_start,8,5,4,a2aa05227,2714.1113,1747.9579,655.2620
|
|
138
|
+
startup,ruby_cold_start,1,6,1,072516af1,4840.6069,3695.6260,2342.2680
|
|
139
|
+
startup,ruby_cold_start,8,6,2,a2aa05227,2797.9314,1771.7330,618.9530
|
|
140
|
+
startup,ruby_cold_start,1,6,3,a2aa05227,4958.5187,3911.7851,2740.9570
|
|
141
|
+
startup,ruby_cold_start,8,6,4,072516af1,3304.2609,1861.4969,535.6080
|
|
142
|
+
startup,ruby_cold_start,8,7,1,a2aa05227,4279.9940,2957.7951,1327.4190
|
|
143
|
+
startup,ruby_cold_start,8,7,2,072516af1,3307.4885,2225.9429,903.3250
|
|
144
|
+
startup,ruby_cold_start,1,7,3,072516af1,4818.5909,3786.2060,2433.6520
|
|
145
|
+
startup,ruby_cold_start,1,7,4,a2aa05227,4896.0249,3884.1662,2720.8570
|
|
146
|
+
startup,ruby_cold_start,8,8,1,072516af1,2882.8863,1920.8450,564.8240
|
|
147
|
+
startup,ruby_cold_start,1,8,2,a2aa05227,5527.5349,4237.0250,3121.7020
|
|
148
|
+
startup,ruby_cold_start,8,8,3,a2aa05227,2455.4755,1453.3529,576.0990
|
|
149
|
+
startup,ruby_cold_start,1,8,4,072516af1,4776.8673,3748.6720,2416.7040
|
|
@@ -182,3 +182,61 @@ bundle exec ruby -Ilib benchmark/profile_mir_generation_allocations.rb \
|
|
|
182
182
|
- 詳細タイマーを入れたライブラリでoptimizer・inlining・register initializationの既存テストを実行し、24 tests / 5,872 assertions、失敗0。メソッドの `source_location` もコピー側を指すことを確認した。
|
|
183
183
|
- 4種類のi32-chainをCRubyのEfflorescenceとWasmtimeで実行し、入力123に対する結果が `123 + N` と一致した。
|
|
184
184
|
- 計測スクリプトの構文、保存JSONの解析・sample数・IR統計、ドキュメントへのリンクを確認した。
|
|
185
|
+
|
|
186
|
+
## Spinelでの関数単位の並列生成(2026-11-19)
|
|
187
|
+
|
|
188
|
+
macOS arm64、Spinel `a2aa05227`、`make spinel` の既定オプションで、上記の Ruby 3.4.2 fixture(8,161 関数)を使用した。タグ `v1.3.0` と変更後の CLI を比較した。各条件で毎回新しいプロセスを起動し、MIR キャッシュを使わず、条件の順序を往復させてウォームアップ 1 回の後に 5 回測定した。全回で標準出力は `42`、終了コードは 0。
|
|
189
|
+
|
|
190
|
+
```sh
|
|
191
|
+
WARDITE_TRACE=1 WARDITE_MIR_WORKERS=8 SPINEL_WORKERS=8 \
|
|
192
|
+
build/wardite -- tmp/ruby.wasm --disable-gems -e 'puts 6*7'
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
| 条件 | semantic MIR 生成 | モジュールロード全体 | プロセス起動から終了まで |
|
|
196
|
+
| --- | ---: | ---: | ---: |
|
|
197
|
+
| v1.3.0 | 1.310 s | 1.864 s | 2.469 s |
|
|
198
|
+
| 1 ワーカー | 1.505 s | 2.134 s | 2.777 s |
|
|
199
|
+
| 2 ワーカー | 0.827 s | 1.458 s | 2.101 s |
|
|
200
|
+
| 4 ワーカー | 0.457 s | 1.082 s | 1.723 s |
|
|
201
|
+
| 8 ワーカー | 0.394 s | 1.021 s | 1.666 s |
|
|
202
|
+
| 環境変数未指定 | 0.391 s | 1.029 s | 1.669 s |
|
|
203
|
+
|
|
204
|
+
値は中央値。タグ版の MIR 生成時間だけは、同じタグの `Translator#translate` に単調時計の計測を追加した別ビルドで測った。8 ワーカーではタグ版比で MIR 生成が 70%、プロセス全体が 33% 短縮した。変更後は Spinel のスレッド対応ランタイムをリンクするため、1 ワーカーでのプロセス全体はタグ版より 12% 遅かった。ゲストの実行時間が中心の `i32_mix.wat` の `call_mix(10000000, 123)` はタグ版 219.84 ms、変更後の既定設定 220.80 ms。同じ関数の反復 0 回では 3.67 ms から 4.24 ms になった(各 9 回の中央値)。
|
|
205
|
+
|
|
206
|
+
`ruby.wasm` の MIR2 ファイルはタグ版と 8 ワーカー版で 83,817,292 バイトすべてが一致した(SHA-256 `9e52cc9ec5e4c65dc725cf5128330f19670f9df0cc1030cdda4c5ea66c839c8a`)。Base64 の WASI モジュールでもタグ版と 1・2・4・8 ワーカー版の MIR2 ファイルが一致した。
|
|
207
|
+
|
|
208
|
+
### 配布ビルドで確認したコストと採用判断
|
|
209
|
+
|
|
210
|
+
大きい Wasm のコールド起動短縮を優先し、Spinel のスレッド対応ビルドを採用する。今後もスレッド対応を必要とするため、次の 3 ケースで観測した実行時間の増加は許容する。macOS arm64 で Homebrew の v1.3.0 と同じ配布手順で Zig ビルドした PR 版(8 ワーカー)を比較した。各 8 回の平均で、出力の SHA-256 は一致した。
|
|
211
|
+
|
|
212
|
+
| WASI 入力 | Homebrew v1.3.0 | PR 配布用ビルド | 増加 |
|
|
213
|
+
| --- | ---: | ---: | ---: |
|
|
214
|
+
| Base64 decode・4 MiB | 326.0 ms | 349.8 ms | 7.3% |
|
|
215
|
+
| PNG grayscale・1024 × 1024 | 254.7 ms | 257.4 ms | 1.1% |
|
|
216
|
+
| Base64 encode・4 MiB | 419.5 ms | 425.8 ms | 1.5% |
|
|
217
|
+
|
|
218
|
+
原因の切り分けには Apple Clang・`-O2` を使った。v1.3.0 に条件付きの `Thread.new` を加えてスレッド対応ビルドを作り、実行時にはその分岐を通さずに計測した。Base64 encode の総時間からモジュールロード時間を引いた値は、元のタグ版で 348.2 ms、対照版で 378.2 ms、PR の 8 ワーカー版で 378.5 ms だった。約 30 ms の差はワーカーを起動せずに再現した。スレッド対応コード内での各処理の寄与は未計測。
|
|
219
|
+
|
|
220
|
+
### Spinel の固定版更新後の配布ビルド
|
|
221
|
+
|
|
222
|
+
Wardite `0b56dda` のソースを共通にして、旧固定版と新固定版の Spinel で macOS arm64 配布用 CLI をビルドした。Apple M3 Pro、macOS 27.2.1、Apple Clang 21.0.0、`-O2`、macOS デプロイメントターゲット 13.0。MIR キャッシュを使わず、`WARDITE_TRACE=1 WARDITE_MIR_WORKERS=8 SPINEL_WORKERS=8` で毎回新しいプロセスを起動した。
|
|
223
|
+
|
|
224
|
+
| ワークロード | `a2aa05227` | `072516af1` | 経過時間の変化 |
|
|
225
|
+
| --- | ---: | ---: | ---: |
|
|
226
|
+
| Base64 encode・4 MiB | 557.3 ms | 515.9 ms | −7.4% |
|
|
227
|
+
| Base64 decode・元データ 4 MiB | 427.8 ms | 409.8 ms | −4.2% |
|
|
228
|
+
| PNG グレースケール・1024 × 1024 | 350.3 ms | 329.5 ms | −6.0% |
|
|
229
|
+
| Ruby 3.4.2 Wasm・コールド起動 | 2.885 s | 3.082 s | +6.8% |
|
|
230
|
+
|
|
231
|
+
値はプロセス起動から終了までの中央値。各バイナリを 2 回ウォームアップし、ペア内で先に走らせる版を同数にして順序を無作為化した。Base64 と PNG は各 16 回、Ruby は各 10 回。Base64 はエンコード済み・デコード済みの fixture、PNG は Wasmtime の出力とバイト単位で一致した。Ruby の `--disable-gems -e 'puts 6*7'` は両版で `42` を出力した。
|
|
232
|
+
|
|
233
|
+
Ruby の起動を追加で計測した。Spinel のワーカー数は 8 に固定し、MIR ワーカー数を 1・8 に変えた。ウォームアップ各 1 回の後、4 条件が各実行位置に同じ回数現れる順序で各 8 回測定した。次の値も中央値で、ロード時間には semantic MIR 生成を含む。
|
|
234
|
+
|
|
235
|
+
| MIR ワーカー数 | semantic MIR 生成(旧 → 新) | モジュールロード(旧 → 新) | 起動から終了まで(旧 → 新) |
|
|
236
|
+
| ---: | ---: | ---: | ---: |
|
|
237
|
+
| 1 | 2.731 → 2.334 s | 3.898 → 3.680 s | 4.913 → 4.753 s |
|
|
238
|
+
| 8 | 0.637 → 0.551 s | 1.713 → 1.871 s | 2.704 → 2.857 s |
|
|
239
|
+
|
|
240
|
+
8 ワーカーでは semantic MIR 生成が短縮した一方、ロード全体とプロセス全体は長くなった。今回の比較には両固定版間の Spinel の変更をすべて含む。TLS 最適化単独の寄与は未測定。
|
|
241
|
+
|
|
242
|
+
Base64 と PNG のゲスト・入力は wardite-benches `f07c454`、Ruby は本ページ冒頭の Ruby 3.4.2 fixture を使った。[全サンプルの CSV](../benchmark/results/spinel-072516af1.csv)・[WASI ベンチのソース](https://github.com/udzura/wardite-benches/tree/f07c4548e3caba59ccdfd16f8f888ebb6af40f95)
|
|
@@ -16,13 +16,13 @@ CRubyのホストAPIは `Memory#data` のStringを引き続き使える。両ホ
|
|
|
16
16
|
|
|
17
17
|
## ビルド
|
|
18
18
|
|
|
19
|
-
WarditeのCIは [Spinel upstreamの `
|
|
19
|
+
WarditeのCIは [Spinel upstreamの `072516af1`](https://github.com/matz/spinel/commit/072516af13322849eabe107eeb910e43fb2882be) に固定する。このリビジョンは `IO::Buffer.new` の領域割り当て失敗を `IO::Buffer::AllocationError` として伝える。CIはコミットとビルド環境でツールチェーンを識別し、Actionsキャッシュ、`main` の成功済み実行のArtifact、ソースからのビルドの順で取得する。インストール一式の `spinel.tar.gz` は、保存元のActions実行ページからダウンロードできる。Artifactにはリポジトリの既定の保持期間を適用する。
|
|
20
20
|
|
|
21
21
|
同じリビジョンをローカルでビルドするには、クローン先のパスを `spinel_src` に指定し、Warditeのルートから実行する。
|
|
22
22
|
|
|
23
23
|
```sh
|
|
24
24
|
git clone https://github.com/matz/spinel.git "$spinel_src"
|
|
25
|
-
git -C "$spinel_src" switch --detach
|
|
25
|
+
git -C "$spinel_src" switch --detach 072516af13322849eabe107eeb910e43fb2882be
|
|
26
26
|
make -C "$spinel_src" deps
|
|
27
27
|
make -C "$spinel_src" all
|
|
28
28
|
make spinel SPINEL="$spinel_src/bin/spinel"
|
|
@@ -209,10 +209,11 @@ module Wardite
|
|
|
209
209
|
|
|
210
210
|
# @rbs instance: Wardite::Instance
|
|
211
211
|
# @rbs source: ModuleSource
|
|
212
|
-
|
|
212
|
+
# @rbs entries: Array[FunctionEntry]
|
|
213
|
+
def initialize(instance, source = ModuleSource.new(instance), entries = [])
|
|
213
214
|
@source = source
|
|
214
215
|
@instance = instance
|
|
215
|
-
@entries =
|
|
216
|
+
@entries = entries
|
|
216
217
|
@stack, @controls = [], []
|
|
217
218
|
@constants = {}
|
|
218
219
|
@i64_constants = nil
|
|
@@ -255,15 +256,100 @@ module Wardite
|
|
|
255
256
|
# @rbs return: Wardite::Efflorescence::IR
|
|
256
257
|
def translate(linked = link)
|
|
257
258
|
@entries = linked.entries
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
259
|
+
trace = ENV["WARDITE_TRACE"]
|
|
260
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC) if trace
|
|
261
|
+
configured = ENV["WARDITE_MIR_WORKERS"]
|
|
262
|
+
# CRuby serializes Ruby translation under the GVL. On Spinel, avoid
|
|
263
|
+
# starting helpers for tiny modules unless explicitly requested.
|
|
264
|
+
workers = if configured
|
|
265
|
+
configured.to_i.clamp(1, 8)
|
|
266
|
+
elsif RUBY_ENGINE == "spinel" && @entries.size - linked.hosts.size >= 32
|
|
267
|
+
(ENV["SPINEL_WORKERS"] || "8").to_i.clamp(1, 8)
|
|
268
|
+
else
|
|
269
|
+
1
|
|
270
|
+
end
|
|
271
|
+
functions = if workers > 1
|
|
272
|
+
translate_parallel(workers)
|
|
273
|
+
else
|
|
274
|
+
translate_range(0, @entries.size)
|
|
275
|
+
end
|
|
276
|
+
if started
|
|
277
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
278
|
+
$stderr.puts "semantic MIR translation: #{elapsed}"
|
|
263
279
|
end
|
|
264
280
|
IR.new(functions, entries: @entries, hosts: linked.hosts)
|
|
265
281
|
end
|
|
266
282
|
|
|
283
|
+
# Partition in module order by decoded instruction count. Each translator
|
|
284
|
+
# owns its stacks and output. Only linked declarations are shared.
|
|
285
|
+
# @rbs workers: Integer
|
|
286
|
+
# @rbs return: Array[Function]
|
|
287
|
+
def translate_parallel(workers)
|
|
288
|
+
store = @instance.store.funcs
|
|
289
|
+
total = 0
|
|
290
|
+
store.each { |wasm| total += wasm.body.size if wasm.is_a?(Wardite::WasmFunction) }
|
|
291
|
+
target = (total + workers - 1) / workers
|
|
292
|
+
starts = [0]
|
|
293
|
+
accumulated = 0
|
|
294
|
+
store.each_with_index do |wasm, index|
|
|
295
|
+
next unless wasm.is_a?(Wardite::WasmFunction)
|
|
296
|
+
if accumulated >= target && accumulated > 0 && starts.size < workers
|
|
297
|
+
starts << index
|
|
298
|
+
accumulated = 0
|
|
299
|
+
end
|
|
300
|
+
accumulated += wasm.body.size
|
|
301
|
+
end
|
|
302
|
+
threads = [] #: Array[Thread]
|
|
303
|
+
begin
|
|
304
|
+
(starts.size - 1).times do |i|
|
|
305
|
+
threads << start_translation(starts.fetch(i), starts.fetch(i + 1))
|
|
306
|
+
end
|
|
307
|
+
tail = translate_range(starts.last || 0, store.size)
|
|
308
|
+
ensure
|
|
309
|
+
# Wait for every worker even when several ranges fail. The earliest
|
|
310
|
+
# range in module order has the same error as serial translation.
|
|
311
|
+
error = nil #: StandardError?
|
|
312
|
+
threads.each do |thread|
|
|
313
|
+
begin
|
|
314
|
+
thread.join
|
|
315
|
+
rescue StandardError => failure
|
|
316
|
+
error ||= failure
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
raise error if error
|
|
320
|
+
end
|
|
321
|
+
functions = [] #: Array[Function]
|
|
322
|
+
threads.each { |thread| functions.concat(thread.value) }
|
|
323
|
+
functions.concat(tail)
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# @rbs first: Integer
|
|
327
|
+
# @rbs limit: Integer
|
|
328
|
+
# @rbs return: Thread
|
|
329
|
+
def start_translation(first, limit)
|
|
330
|
+
worker = Translator.new(@instance, @source, @entries)
|
|
331
|
+
Thread.new do
|
|
332
|
+
Thread.current.report_on_exception = false
|
|
333
|
+
worker.translate_range(first, limit)
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# @rbs first: Integer
|
|
338
|
+
# @rbs limit: Integer
|
|
339
|
+
# @rbs return: Array[Function]
|
|
340
|
+
def translate_range(first, limit)
|
|
341
|
+
functions = [] #: Array[Function]
|
|
342
|
+
index = first
|
|
343
|
+
while index < limit
|
|
344
|
+
wasm = @instance.store.funcs.fetch(index)
|
|
345
|
+
if wasm.is_a?(Wardite::WasmFunction)
|
|
346
|
+
functions << translate_function(wasm, index, @entries.fetch(index).defined_index)
|
|
347
|
+
end
|
|
348
|
+
index += 1
|
|
349
|
+
end
|
|
350
|
+
functions
|
|
351
|
+
end
|
|
352
|
+
|
|
267
353
|
# Replay the original declarations without re-linking host functions,
|
|
268
354
|
# executing start, or consulting live global/memory/table slots.
|
|
269
355
|
# @rbs linked: IR
|
data/lib/wardite/version.rb
CHANGED
data/scripts/build_spinel_zig.rb
CHANGED
|
@@ -33,7 +33,7 @@ elsif ARGV.first == "ar"
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# Keep this revision in sync with the Spinel job in runtime-tests.yml.
|
|
36
|
-
SPINEL_REF = "
|
|
36
|
+
SPINEL_REF = "072516af13322849eabe107eeb910e43fb2882be"
|
|
37
37
|
|
|
38
38
|
def run(*command, **options)
|
|
39
39
|
system(*command, **options, exception: true)
|
|
@@ -70,7 +70,10 @@ FileUtils.mkdir_p(root)
|
|
|
70
70
|
root = File.realpath(root)
|
|
71
71
|
ENV["ZIG_GLOBAL_CACHE_DIR"] ||= File.join(root, "zig-global")
|
|
72
72
|
ENV["ZIG_LOCAL_CACHE_DIR"] ||= File.join(root, "zig-local")
|
|
73
|
-
|
|
73
|
+
native_macos = targets.include?("aarch64-macos") &&
|
|
74
|
+
%w[arm64 aarch64].include?(RbConfig::CONFIG["host_cpu"]) &&
|
|
75
|
+
!ENV["CI"] && !ENV["GITHUB_ACTIONS"]
|
|
76
|
+
run(ENV.fetch("ZIG"), "version") unless native_macos && targets.uniq == ["aarch64-macos"]
|
|
74
77
|
|
|
75
78
|
File.open(File.join(root, "build.lock"), "a") do |lock|
|
|
76
79
|
lock.flock(File::LOCK_EX)
|
|
@@ -84,14 +87,19 @@ File.open(File.join(root, "build.lock"), "a") do |lock|
|
|
|
84
87
|
end
|
|
85
88
|
end
|
|
86
89
|
|
|
87
|
-
host
|
|
90
|
+
# The native executable links the host runtime. Cache its objects by
|
|
91
|
+
# deployment target so a previous host build cannot raise the minimum OS.
|
|
92
|
+
host = File.join(root, native_macos ? "host-arm64-macos.#{macos}-#{SPINEL_REF}" : "host-#{SPINEL_REF}")
|
|
88
93
|
unpack(archive, host)
|
|
89
94
|
spinel = File.join(host, "bin", "spinel")
|
|
90
|
-
inputs = ["lib/
|
|
95
|
+
inputs = ["lib/libspinel_rt_mt.a", "packages/stringio/sp_stringio_mt.o"]
|
|
91
96
|
submake = [make, "-j#{jobs}", "NO_CCACHE=1"]
|
|
92
97
|
make_env = {"MAKEFLAGS" => nil, "MFLAGS" => nil}
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
native_env = {"MACOSX_DEPLOYMENT_TARGET" => macos, "CC" => "/usr/bin/clang"}
|
|
99
|
+
host_env = native_macos ? make_env.merge(native_env) : make_env
|
|
100
|
+
run(host_env, *submake, "-C", host, "deps")
|
|
101
|
+
# Spinel locates its lib directory by probing for the single-thread archive.
|
|
102
|
+
run(host_env, *submake, "-C", host, "bin/spinel", "lib/libspinel_rt.a", *inputs)
|
|
95
103
|
|
|
96
104
|
script = [RbConfig.ruby, File.expand_path(__FILE__)]
|
|
97
105
|
cc = Shellwords.join([*script, "cc"])
|
|
@@ -100,20 +108,24 @@ File.open(File.join(root, "build.lock"), "a") do |lock|
|
|
|
100
108
|
target = supported_targets.fetch(name)
|
|
101
109
|
output = File.join(root, target)
|
|
102
110
|
FileUtils.mkdir_p(output)
|
|
103
|
-
runtime = File.join(output, "spinel-#{SPINEL_REF}")
|
|
104
|
-
unpack(archive, runtime)
|
|
105
|
-
env = {
|
|
106
|
-
"WARDITE_ZIG_TARGET" => target,
|
|
107
|
-
"WARDITE_SPINEL_HOST" => host,
|
|
108
|
-
"WARDITE_SPINEL_RUNTIME" => runtime
|
|
109
|
-
}
|
|
110
111
|
puts "Building Wardite for #{target}"
|
|
111
|
-
run(make_env.merge(env), *submake, "-C", runtime, "CC=#{cc}", "AR_DET=#{ar}", *inputs)
|
|
112
112
|
Dir.mktmpdir("wardite-", output) do |staging|
|
|
113
113
|
binary = File.join(staging, "wardite")
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
args = [spinel, "-I", "lib", "--strict-require", *Shellwords.split(spinel_flags)]
|
|
115
|
+
if native_macos && name == "aarch64-macos"
|
|
116
|
+
run(native_env, *args, "--cc=/usr/bin/clang", "exe/wardite", "-o", binary)
|
|
117
|
+
else
|
|
118
|
+
runtime = File.join(output, "spinel-#{SPINEL_REF}")
|
|
119
|
+
unpack(archive, runtime)
|
|
120
|
+
env = {
|
|
121
|
+
"WARDITE_ZIG_TARGET" => target,
|
|
122
|
+
"WARDITE_SPINEL_HOST" => host,
|
|
123
|
+
"WARDITE_SPINEL_RUNTIME" => runtime
|
|
124
|
+
}
|
|
125
|
+
run(make_env.merge(env), *submake, "-C", runtime, "CC=#{cc}", "AR_DET=#{ar}", *inputs)
|
|
126
|
+
run(env, *args, "--cc=#{cc}", "--jobs=#{jobs}", "--split-parts=#{[jobs.to_i * 3, 64].min}",
|
|
127
|
+
"exe/wardite", "-o", binary)
|
|
128
|
+
end
|
|
117
129
|
File.rename(binary, File.join(output, "wardite"))
|
|
118
130
|
end
|
|
119
131
|
puts File.join(output, "wardite")
|
|
@@ -87,7 +87,8 @@ module Wardite
|
|
|
87
87
|
|
|
88
88
|
# @rbs instance: Wardite::Instance
|
|
89
89
|
# @rbs source: ModuleSource
|
|
90
|
-
|
|
90
|
+
# @rbs entries: Array[FunctionEntry]
|
|
91
|
+
def initialize: (Wardite::Instance instance, ?ModuleSource source, ?Array[FunctionEntry] entries) -> untyped
|
|
91
92
|
|
|
92
93
|
# @rbs return: Wardite::Efflorescence::IR
|
|
93
94
|
def link: () -> Wardite::Efflorescence::IR
|
|
@@ -96,6 +97,22 @@ module Wardite
|
|
|
96
97
|
# @rbs return: Wardite::Efflorescence::IR
|
|
97
98
|
def translate: (?Wardite::Efflorescence::IR linked) -> Wardite::Efflorescence::IR
|
|
98
99
|
|
|
100
|
+
# Partition in module order by decoded instruction count. Each translator
|
|
101
|
+
# owns its stacks and output. Only linked declarations are shared.
|
|
102
|
+
# @rbs workers: Integer
|
|
103
|
+
# @rbs return: Array[Function]
|
|
104
|
+
def translate_parallel: (Integer workers) -> Array[Function]
|
|
105
|
+
|
|
106
|
+
# @rbs first: Integer
|
|
107
|
+
# @rbs limit: Integer
|
|
108
|
+
# @rbs return: Thread
|
|
109
|
+
def start_translation: (Integer first, Integer limit) -> Thread
|
|
110
|
+
|
|
111
|
+
# @rbs first: Integer
|
|
112
|
+
# @rbs limit: Integer
|
|
113
|
+
# @rbs return: Array[Function]
|
|
114
|
+
def translate_range: (Integer first, Integer limit) -> Array[Function]
|
|
115
|
+
|
|
99
116
|
# Replay the original declarations without re-linking host functions,
|
|
100
117
|
# executing start, or consulting live global/memory/table slots.
|
|
101
118
|
# @rbs linked: IR
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wardite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Uchio Kondo
|
|
@@ -116,6 +116,7 @@ files:
|
|
|
116
116
|
- benchmark/results/real-workloads-baseline-2026-11-18.json
|
|
117
117
|
- benchmark/results/selective_reset_spinel_2026-11-04.json
|
|
118
118
|
- benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json
|
|
119
|
+
- benchmark/results/spinel-072516af1.csv
|
|
119
120
|
- benchmark/results/spinel_fetch_root_patch_2026-11-04.json
|
|
120
121
|
- benchmark/results/stack-vm-removal.json
|
|
121
122
|
- benchmark/results/while_final_compiler_comparison_2026-11-04.json
|