A self-hosted Convex operator describes compiling existing TypeScript queries and mutations into WebAssembly rather than rewriting the application in Rust or interpreting JavaScript inside a Wasm runtime. The motivation is the cost of running functions in V8: fast execution depends on keeping many warmed contexts, which can retain around 35 MB each and consume roughly 14 GB of server memory in this deployment. Deployments can invalidate those contexts, triggering bursts of module loading and compilation while clients also rerun affected queries. V8 isolate workers, Convex’s Tokio workers, and V8 background threads also compete for CPU, slowing functions under load.
The new compiler, convex-wasm-compiler, is reported to make queries and mutations twice as fast on average, reduce tail latency threefold, and cut memory retained by resident execution environments by 80%. It leaves application code in TypeScript using the Convex SDK, and begins its pipeline by identifying Convex function registrations, bundling dependencies with esbuild, and analyzing source and dependencies with Rust and Oxc. The accompanying convex-backend change runs compiled functions with Wasmtime fibers on the existing Tokio runtime. The project took nearly three months, with integrating Wasmtime accounting for only a small share of the effort; compiling the TypeScript application was the larger challenge. The account also explains why this approach was chosen over a Rust rewrite: it avoids a disruptive migration and aims to complement future Convex development.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.