wasm-bindgen-lite 0.3.0 → 0.3.2
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.
- package/README.md +78 -0
- package/bin/wasm-bindgen-lite.js +12 -1
- package/package.json +4 -1
- package/src/cli/bench.js +887 -0
- package/src/cli/build.js +61 -9
- package/src/cli/config.js +9 -1
- package/src/cli/emit.js +121 -64
- package/src/cli/index.js +30 -1
- package/src/js/browser-inline.js +23 -10
- package/src/js/browser.js +22 -17
- package/src/js/node-inline.js +23 -10
- package/src/js/node.js +21 -12
- package/src/js/util.js +30 -0
package/README.md
CHANGED
|
@@ -272,6 +272,35 @@ Specify it in your config:
|
|
|
272
272
|
|
|
273
273
|
`wasm-bindgen-lite` automatically compiles your Rust code with SIMD features enabled for the `.simd.wasm` target. The runtime detects support and picks the optimal binary.
|
|
274
274
|
|
|
275
|
+
#### SIMD-First Lazy Loading
|
|
276
|
+
|
|
277
|
+
The runtime uses a **SIMD-first, lazy-baseline** loading strategy:
|
|
278
|
+
|
|
279
|
+
1. **Only the SIMD artifact is fetched initially** (saves bandwidth)
|
|
280
|
+
2. If SIMD instantiation fails (e.g., on older browsers), the baseline is fetched as a fallback
|
|
281
|
+
3. On SIMD-capable environments, the baseline is **never downloaded**
|
|
282
|
+
|
|
283
|
+
This means most users only download one WASM file instead of both.
|
|
284
|
+
|
|
285
|
+
#### Forcing a Specific Backend (for Benchmarking)
|
|
286
|
+
|
|
287
|
+
For consistent performance testing, you can force the runtime to use a specific backend:
|
|
288
|
+
|
|
289
|
+
```javascript
|
|
290
|
+
import { init, my_transform } from 'my-wasm-pkg'
|
|
291
|
+
|
|
292
|
+
// Force baseline (non-SIMD) for comparison
|
|
293
|
+
await init({}, { backend: 'base' })
|
|
294
|
+
|
|
295
|
+
// Force SIMD (will throw if not supported)
|
|
296
|
+
await init({}, { backend: 'simd' })
|
|
297
|
+
|
|
298
|
+
// Auto-detect (default behavior)
|
|
299
|
+
await init({}, { backend: 'auto' })
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
This is useful for A/B benchmarking SIMD vs baseline performance in the same environment.
|
|
303
|
+
|
|
275
304
|
### Streaming Processing
|
|
276
305
|
|
|
277
306
|
Use `createTransformStream()` for high-performance data pipelines:
|
|
@@ -300,6 +329,55 @@ Options:
|
|
|
300
329
|
--wasm-opt-args Custom args for wasm-opt
|
|
301
330
|
```
|
|
302
331
|
|
|
332
|
+
### SIMD Variant Analysis
|
|
333
|
+
|
|
334
|
+
Build a matrix of WASM variants and analyze SIMD usage:
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
wasm-bindgen-lite bench [options]
|
|
338
|
+
|
|
339
|
+
Options:
|
|
340
|
+
--crate <path> Path to Rust crate (default: ".")
|
|
341
|
+
--clean Clean output directory before building
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
The `bench` command builds variants based on your SIMD feature configuration and produces:
|
|
345
|
+
|
|
346
|
+
- **Variant matrix**: scalar, autovec, explicit-* (per feature), explicit-all
|
|
347
|
+
- **SIMD analysis**: Counts SIMD opcodes in each variant
|
|
348
|
+
- **Provenance detection**: Identifies compiler-added vs explicit SIMD instructions
|
|
349
|
+
- **Reports**: JSON and HTML reports in `bench_out/`
|
|
350
|
+
|
|
351
|
+
#### SIMD Configuration
|
|
352
|
+
|
|
353
|
+
Add this to your `wasm-bindgen-lite.config.json`:
|
|
354
|
+
|
|
355
|
+
```json
|
|
356
|
+
{
|
|
357
|
+
"simd": {
|
|
358
|
+
"features": {
|
|
359
|
+
"explicit-simd-encode": { "name": "encode" },
|
|
360
|
+
"explicit-simd-decode": { "name": "decode" }
|
|
361
|
+
},
|
|
362
|
+
"allFeature": "explicit-simd"
|
|
363
|
+
},
|
|
364
|
+
"bench": {
|
|
365
|
+
"outputDir": "bench_out"
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
This generates 5 variants:
|
|
371
|
+
- **scalar**: No SIMD (`opt-level=3` only)
|
|
372
|
+
- **autovec**: LLVM autovectorization (`+simd128` but no explicit features)
|
|
373
|
+
- **explicit-encode**: `explicit-simd-encode` feature enabled
|
|
374
|
+
- **explicit-decode**: `explicit-simd-decode` feature enabled
|
|
375
|
+
- **explicit-all**: `explicit-simd` meta-feature (all SIMD)
|
|
376
|
+
|
|
377
|
+
The provenance analysis shows how many SIMD instructions were added by:
|
|
378
|
+
- **Compiler**: autovec.simd_ops - scalar.simd_ops
|
|
379
|
+
- **Explicit code**: explicit.simd_ops - autovec.simd_ops
|
|
380
|
+
|
|
303
381
|
## Examples
|
|
304
382
|
|
|
305
383
|
- [node-basic](./examples/node-basic): Minimal Node.js setup.
|
package/bin/wasm-bindgen-lite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { runBuild, runClean, printHelp } from '../src/cli/index.js'
|
|
2
|
+
import { runBuild, runClean, runBenchCmd, printHelp } from '../src/cli/index.js'
|
|
3
3
|
|
|
4
4
|
function parseArgs(raw) {
|
|
5
5
|
const [command, ...rest] = raw
|
|
@@ -51,6 +51,12 @@ function parseArgs(raw) {
|
|
|
51
51
|
case '--no-update-package-json':
|
|
52
52
|
opts.updatePackageJson = false
|
|
53
53
|
break
|
|
54
|
+
case '--clean':
|
|
55
|
+
opts.clean = true
|
|
56
|
+
break
|
|
57
|
+
case '--skip-build':
|
|
58
|
+
opts.skipBuild = true
|
|
59
|
+
break
|
|
54
60
|
case '--help':
|
|
55
61
|
case '-h':
|
|
56
62
|
opts.help = true
|
|
@@ -90,6 +96,11 @@ async function main() {
|
|
|
90
96
|
return
|
|
91
97
|
}
|
|
92
98
|
|
|
99
|
+
if (command === 'bench') {
|
|
100
|
+
await runBenchCmd(opts)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
93
104
|
console.error(`Unknown command: ${command}`)
|
|
94
105
|
printHelp()
|
|
95
106
|
process.exitCode = 1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wasm-bindgen-lite",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI tool to build Rust crates into minimal, SIMD-optimized WASM packages with JS loaders",
|
|
6
6
|
"repository": {
|
|
@@ -56,5 +56,8 @@
|
|
|
56
56
|
},
|
|
57
57
|
"exports": {
|
|
58
58
|
".": "./src/cli/index.js"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"typescript": "^5.9.3"
|
|
59
62
|
}
|
|
60
63
|
}
|