You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds examples/jz-kernel. jz compiles a JavaScript-subset numeric kernel to standard WebAssembly; EdgeJS loads it through WebAssembly.Module / WebAssembly.Instance. JZ is used as a kernel compiler, not as a JavaScript engine for EdgeJS.
Reproduce
From examples/jz-kernel:
npm ci
edge bench.mjs
Local EdgeJS native result (4x4 Float64Array matrix kernel, 200k iterations, 9 runs after 5 warmups):
imports: 0
wasmBytes: 919
checksum: 50495773 (raw JS == JZ WASM)
raw JS median: ~12.6 ms
JZ WASM median: ~8.3 ms
Limits
Not an EdgeJS engine integration.
No safe-mode claim; local safe-mode is blocked before user code by missing Wasmer N-API features (napi_v10 / napi_extension_wasmer_v0).
No CI; the example would need a networked install of jz@^0.1.1.
The reason will be displayed to describe this comment to others. Learn more.
Awesome, great first step.
Ideally I'd like to see JZ as another engine supported by Edge.js. But perhaps that might be better done in another PR. Thoughts @dy ?
@syrusakbary so how do you see JZ integration the best way? I lean to option 2, I could fix compat layer.
Some node modules can be added via WASI: fs, time, crypto. Some host env import can enable simplified fetch.
Also I am finishing metacircularity (jz.wasm) - that needs to be done before integration.
Integrating jz as an alternative JS engine in edgejs is fundamentally different from integrating V8, JavaScriptCore, or QuickJS.
The Core Mismatch
Edge.js is built around N-API (Node-API). It boots up by evaluating complex dynamic JavaScript (lib/internal/bootstrap/*.js) using napi_run_script, creating dynamic objects, closures, and managing Garbage Collection.
jz is a static compiler for a numeric/array subset of JS with no GC, no object prototypes. It outputs raw WebAssembly.
Therefore, jz cannot act as a full napi/jz provider to boot Node.js core modules (fs, http, etc.). It would fail to process EdgeJS's own internal Javascript.
How Integration Is Possible
Despite the mismatch, jz can be integrated at a different architectural level. Here are the realistic paths:
1. The "Sub-Engine" (AOT Kernel Compiler)
EdgeJS retains V8/QuickJS as its primary runtime (to handle N-API and Node compatibility) but embeds jz natively to accelerate pure math/DSP/array workloads.
EdgeJS intercepts imports (e.g. files with "use jz" or .jz extensions).
EdgeJS automatically runs the jz compiler on the script.
It instantiates the resulting WASM via Wasmer instantly and returns standard JS wrappers.
Pros: Seamless DX. Users get native Node.js capabilities + instant WASM speeds for hot routines.
2. The "Bare-Metal WASI" Engine Mode (edge --engine=jz)
EdgeJS bypasses standard Node initialization entirely if jz is selected.
Command: edge run --engine=jz compute.js
Under the hood, EdgeJS runs the jz compiler (either using a tiny embedded QuickJS instance or pre-compiled JZ-in-WASM).
It takes the generated .wasm, hooks it up to Wasmer with WASI context, and runs it.
Pros: Pure, blazing-fast sandbox. No Node.js overhead.
Cons: The script cannot use require('node:fs') or general JS APIs. It is limited to exactly what jz supports + WASI.
3. A Minimal napi/jz Facade (Not Recommended)
You could implement a napi/jz layer where napi_run_script compiles to WASM and primitive types (napi_create_double, etc.) map to WASM memory.
Cons: You'd have to stub out 90% of N-API. EdgeJS wouldn't be able to boot its normal environment.
Summary
As a drop-in replacement for V8 to run standard Node apps that's practically impossible without rewriting JZ into a fully dynamic JIT/interpreter.
However, if the goal is to make EdgeJS the first runtime to natively support "JS-subset to WASM execution" out of the box (either dynamically accelerating hot functions via Option 1, or treating Edge.js as a WASI runner for JS via Option 2), that provides massive value and perfectly fits Edge.js's vision of WASM computing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add JZ WebAssembly kernel example
Adds
examples/jz-kernel.jzcompiles a JavaScript-subset numeric kernel to standard WebAssembly; EdgeJS loads it throughWebAssembly.Module/WebAssembly.Instance. JZ is used as a kernel compiler, not as a JavaScript engine for EdgeJS.Reproduce
From
examples/jz-kernel:Local EdgeJS native result (4x4
Float64Arraymatrix kernel, 200k iterations, 9 runs after 5 warmups):Limits
napi_v10/napi_extension_wasmer_v0).jz@^0.1.1.