Перейти к основному содержимому

Rust→wasm compute kernel (vendored, plugin-free)

Generated from pattern-library/registry.json — do not edit by hand; change the registry and run bun run patterns:build.

Index card — the docs below are the canonical explanation; deep-tier pattern pages additionally carry invariants and emulation notes.

Category: Architecture & Request Pipeline · Tier: light · Maturity: proven (verified 2026-08-20 @ 1a130d67) · Risk: low — browser-only compute, no external services; rebuilds need only podman

Rust crate compiled to wasm in an ephemeral container, artifacts vendored into src/lib/wasm/kernel/, loaded via ?url + explicit init with zero Vite plugins, benchmarked honestly against a line-for-line JS twin with a vitest parity gate.

When to use: Reach for it when a browser workload is compute-dense over typed data (convolution, physics, hashing) and the data can stay resident in wasm linear memory — and to see why string-heavy or per-call-copy workloads should stay in JS.

Docs

Code

  • crates/kernel/src/lib.rs — The Rust kernel — resident buffers, scalars-only boundary, deliberate marshalling counter-example. (GitHub · GitLab)
  • src/lib/wasm/index.ts — The loader: ?url + init({ module_or_path }), dynamic import, singleton — no Vite plugins. (GitHub · GitLab)
  • src/lib/wasm/filters.ts — Line-for-line JS twins of the kernel; integer math keeps both engines byte-identical. (GitHub · GitLab)
  • src/lib/wasm/kernel-bench.worker.ts — Worker shell — handler installed synchronously, counterbalanced warm-up/timed protocol. (GitHub · GitLab)
  • scripts/wasm/build.sh — Ephemeral rust: container build; digest-pinned image + rust-toolchain.toml + Cargo.lock + bindgen version; emits the freshness manifest. (GitHub · GitLab)

Tests

  • src/lib/wasm/kernel-parity.test.ts — Parity gate: committed wasm artifact vs JS twins, byte-identical, loaded under plain Node. (GitHub · GitLab)
  • src/lib/wasm/kernel-manifest.test.ts — Freshness gate: recomputes build-manifest.json hashes so a Rust edit without a rebuild goes red — without Rust in the gate. (GitHub · GitLab)
  • src/lib/wasm/filters.test.ts (GitHub · GitLab)

Proof


Machine-readable record: architecture-wasm-kernel in pattern-library/registry.json.

← Back to Pattern Library

Думаете, этот паттерн можно сделать лучше? Расскажите как.

Оставить отзыв