Add pd-node-embed: Rust/deno_core external for sub-microsecond JS/TS execution #1
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.
Implements a Rust-based Pure Data external embedding deno_core (V8) for ~100ns message latency, enabling audio-rate JavaScript/TypeScript processing. Complements existing IPC-based pd-node (~100μs latency) for control-rate use cases.
Architecture
Pure Data C FFI → Rust → deno_core → V8 → User Script
src/lib.rs: PD external interface (node_embed_setup, lifecycle, message handlers)src/runtime.rs: JsRuntime initialization, TypeScript transpilation (deno_ast), script executionsrc/ops/: Fast ops foroutlet,post,errorusing#[op2(fast)]src/loader.rs: Custom ModuleLoader with TS transpilationjs/bootstrap.js: Sets upglobalThis.pdAPI and console redirectionbuild.rs: Generates PD header bindings via bindgen (fallback to manual)API
Trade-offs
Build
Install by copying to PD externals as
node~.pd_linux/node~.pd_darwin.Future Work
~) inlet/outlet supportOriginal prompt
Overview
Create a new
pd-node-embed/directory with a Rust-based Pure Data external that embedsdeno_core(V8) for near-native JavaScript/TypeScript execution. This provides ~100ns latency (vs ~100μs with the current IPC approach), enabling audio-rate JS processing.Background
The current
pd-nodeuses fork/exec + IPC pipes to communicate with system Bun/Node.js. This works great for control-rate messages but has ~50-100μs latency per message, which is too slow for audio-rate processing.By embedding
deno_core(the core of Deno runtime), we get:Implementation Requirements
1. Project Structure
2. Cargo.toml
3. Core Rust Implementation (src/lib.rs)
Implement the Pure Data external interface:
4. deno_core Runtime (src/runtime.rs)
5. Ops Implementation...
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.