Skip to content

WIP: napi-rs shared-core for Node (WASM stays elsewhere) - #781

Draft
slinkydeveloper wants to merge 1 commit into
restatedev:mainfrom
slinkydeveloper:napi-playing-around
Draft

WIP: napi-rs shared-core for Node (WASM stays elsewhere)#781
slinkydeveloper wants to merge 1 commit into
restatedev:mainfrom
slinkydeveloper:napi-playing-around

Conversation

@slinkydeveloper

Copy link
Copy Markdown
Collaborator

WIP / draft — opening early for visibility; conformance + release-publish still need a real CI run (see below).

What

Run the Rust shared-core as a napi-rs native addon on Node, to escape the wasm32 4 GB memory ceiling users are hitting and to cut buffer copies. Every other runtime (Bun, Deno, Cloudflare Workers, edge, browser) keeps the WASM build, which also stays bundled in @restatedev/restate-sdk as a universal fallback on Node. Behavior is meant to be functionally identical (same restate-sdk-shared-core 7.0.2 + features). For users it's transparent: bump the SDK version.

How

  • New package @restatedev/restate-sdk-shared-core-native/ — napi port of sdk-shared-core-wasm-bindings, exposing the exact same JS surface. Published as per-platform prebuilt binaries (optionalDependencies).
  • restate-sdk selector (src/endpoint/handlers/vm/index.ts) — loads native on Node (runtime detection) and falls back to WASM; the 5 vm.* consumers are repointed. Force with RESTATE_SHARED_CORE=native|wasm.
  • Cloudflare unchanged — the build-time patch swaps in the workerd WASM entrypoint (incl. the cloudflareWorkersBundlerPatch() hack).
  • Copy reduction: &[u8]/Uint8Array in, single-move Buffer out, no base64 decode/instantiate at startup.

CI

  • native.yaml cross-compiles 5 triples (linux gnu+musl x64/arm64, darwin-arm64 — mirrors the Java SDK).
  • test.yml gains a native-parity job (e2e with RESTATE_SHARED_CORE=native).
  • release.yml publishes the native packages via .tools/publish-native.sh, with a Java-SDK-style completeness gate.

Verified locally

pnpm build (all packages), full typecheck, ATTW + api-extractor, lint, prettier, --frozen-lockfile. Native crate compiles; VM executes shared-core with structured errors/headers/enums/buffers correct; selector picks native on Node / WASM elsewhere.

Still to validate

  • Full conformance parity — runs in the native-parity CI job (locally blocked by container networking; native and WASM fail identically there).
  • Release publish flow (.tools/publish-native.sh napi create-npm-dirs/artifacts/prepublish flags) — needs a dry-run with real npm creds.
  • Consider lazy-loading WASM on the native path (currently eagerly imported as the fallback/type source).

🤖 Generated with Claude Code

Run the Rust shared-core as a napi-rs native addon on Node to escape the
wasm32 4GB memory ceiling and reduce buffer copies, while keeping the WASM
build for every other runtime (Bun, Deno, Cloudflare, edge, browser) and as
a universal fallback on Node.

- New package @restatedev/restate-sdk-shared-core-native: napi port of
  sdk-shared-core-wasm-bindings, same restate-sdk-shared-core 7.0.2 + features
  for functional parity, published as per-platform prebuilt binaries.
- restate-sdk: vm/index.ts selector loads native on Node (optionalDependencies
  + runtime detection) and falls back to WASM; the 5 vm consumers are
  repointed. Force with RESTATE_SHARED_CORE=native|wasm.
- Cloudflare Workers unchanged (patch swaps in the workerd WASM entrypoint).
- CI: native.yaml cross-compiles 5 triples (linux gnu+musl x64/arm64,
  darwin-arm64); test.yml gains a native-parity job; release.yml publishes the
  native packages via .tools/publish-native.sh with a completeness gate.

Not yet validated: full conformance parity (runs in CI native-parity job;
locally blocked by container networking) and the release publish flow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant