Transforming interactive scientific notebook cells into compiled WebAssembly binaries. Transpiles custom Octave procedural loops and algorithms into optimized Rust crates, achieving 15x to 60x speedups with native machine-level efficiency.
In standard scientific notebooks, execution speed splits into two distinct performance tiers:
Matrix multiplication (GEMM), SVD, QR, and Parquet decoding run via compiled WebAssembly SIMD kernels at native machine speeds.
User-authored loops (e.g., for i = 1:100000 ... end), custom differential equations, and dynamic array indexing execute through JavaScript AST interpretation.
Every scalar variable lookup and assignment inside an interpreted loop creates temporary JS numbers and scope objects, triggering garbage collection stalls.
Interpreted code cannot benefit from LLVM optimization passes such as loop unrolling, register allocation, auto-vectorization, or dead code elimination.
ForgeCurves introduces an end-to-end 1-click Ahead-of-Time compilation pipeline for active notebook cells:
The client-side transpiler inspects cell code, extracts variable dependency graphs, and infers static array shapes and floating-point types from the active workspace.
Generates an idiomatic, memory-safe Rust crate (notebook_crate) containing type-annotated variables, SIMD loops, and dedicated entry points (run_cell_0, run_cell_1).
Compiles the Rust crate into a dedicated notebook_<id>.wasm binary module through an authenticated cloud build service or a local compiler bridge.
The active Web Worker kernel dynamically instantiates the generated WASM binary, executing subsequent cell evaluations at native machine speed.
In standard Octave, cells share global variables across sequential executions. The AOT compiler preserves this semantics by mapping the notebook workspace into a unified WebAssembly NotebookState struct:
Matrices and vectors are allocated in contiguous linear memory blocks, eliminating pointer chasing and allowing zero-copy sharing between compiled cells.
When a compiled cell finishes executing, updated variable definitions automatically synchronize with the notebook variable inspector (whos) and plotting engine.
Projected and measured execution speedups comparing interpreted JavaScript execution against Ahead-of-Time compiled WebAssembly routines:
| Algorithm Workload | Interpreted Time (ms) | AOT Compiled Time (ms) | Speedup Multiplier | Optimization Factor |
|---|---|---|---|---|
| Iterative Mandelbrot Fractal (100k points) | 1,480.20 ms | 24.60 ms | 60.17x FASTER | Loop Unrolling |
| Monte Carlo Option Pricing (500k paths) | 3,840.50 ms | 82.30 ms | 46.66x FASTER | Register Inlining |
| Euler ODE Numerical Solver (200k steps) | 890.10 ms | 28.40 ms | 31.34x FASTER | Branchless Math |
| Recursive Fibonacci / Tree Search | 520.40 ms | 22.10 ms | 23.55x FASTER | Call Stack Inlining |
| Coordinate-wise Matrix Update Loop | 1,250.80 ms | 68.50 ms | 18.26x FASTER | Bounds Check Removal |
Each notebook cell dynamically tracks its compilation state with visual indicator badges in the editor gutter:
Standard uncompiled cell. Evaluated via the Web Worker JavaScript evaluation loop with pre-compiled BLAS math acceleration.
Transient state while the transpiler analyzes the cell AST and the background build pipeline produces the WASM binary.
Cell logic is compiled into native WebAssembly bytecode. Execution dispatches directly to the compiled entry point at near-metal speed.
Cell source was edited after compilation. Rerunning this cell falls back to interpreted mode automatically until the next compile pass.