<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: cpkxw-dev</title>
    <description>The latest articles on DEV Community by cpkxw-dev (@cpkxwdev).</description>
    <link>https://dev.to/cpkxwdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4180965%2F25aa88db-d4e6-48ff-891c-f00d5031f7eb.png</url>
      <title>DEV Community: cpkxw-dev</title>
      <link>https://dev.to/cpkxwdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cpkxwdev"/>
    <language>en</language>
    <item>
      <title>slashing cold‑start latency of Supabase edge functions with Rust‑WASM</title>
      <dc:creator>cpkxw-dev</dc:creator>
      <pubDate>Tue, 13 Oct 2026 04:31:03 +0000</pubDate>
      <link>https://dev.to/cpkxwdev/slashing-cold-start-latency-of-supabase-edge-functions-with-rust-wasm-2d2m</link>
      <guid>https://dev.to/cpkxwdev/slashing-cold-start-latency-of-supabase-edge-functions-with-rust-wasm-2d2m</guid>
      <description>&lt;p&gt;when you spin up a Supabase Edge Function written in TypeScript, the first request can easily sit on a 300‑400 ms cold‑start. in a product that streams MIDI bytes or pushes real‑time telemetry, that jitter kills user experience. the pattern I keep seeing is: keep the function tiny, compile to native code, and let the edge runtime cache the Wasm module.&lt;/p&gt;

&lt;h2&gt;
  
  
  why the latency spikes
&lt;/h2&gt;

&lt;p&gt;Supabase runs edge functions on Deno, which starts a V8 isolate per function version. the isolate loads the source bundle, resolves imports, and then executes the entry point. each of those steps touches the filesystem and the network, so you get a latency floor that is hard to push below ~200 ms without changing the runtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  the rust‑wasm shortcut
&lt;/h2&gt;

&lt;p&gt;Rust compiles to a single Wasm file with no dynamic imports. when you ship that file as the sole entry point, Deno just loads the binary into the isolate and calls the exported handler. the cost drops to the time needed to deserialize the Wasm module – usually under 50 ms on the Supabase edge.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/lib.rs – minimal edge handler&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;supabase_edge&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;prelude&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[event_handler]&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EdgeError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// echo payload, but keep it sync‑free&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="nf"&gt;.body_bytes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.with_body&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="c"&gt;# Cargo.toml – ensure wasm target&lt;/span&gt;
&lt;span class="nn"&gt;[package]&lt;/span&gt;
&lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"edge_echo"&lt;/span&gt;
&lt;span class="py"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.1.0"&lt;/span&gt;
&lt;span class="py"&gt;edition&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"2021"&lt;/span&gt;

&lt;span class="nn"&gt;[dependencies]&lt;/span&gt;
&lt;span class="py"&gt;supabase-edge&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.2"&lt;/span&gt;

&lt;span class="nn"&gt;[lib]&lt;/span&gt;
&lt;span class="py"&gt;crate-type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"cdylib"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# build for wasm32‑unknown‑unknown&lt;/span&gt;
cargo build &lt;span class="nt"&gt;--release&lt;/span&gt; &lt;span class="nt"&gt;--target&lt;/span&gt; wasm32-unknown-unknown
&lt;span class="c"&gt;# copy the .wasm into the Supabase function folder&lt;/span&gt;
&lt;span class="nb"&gt;cp &lt;/span&gt;target/wasm32-unknown-unknown/release/edge_echo.wasm ./functions/echo/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  deployment tricks
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;use a static &lt;code&gt;deno.json&lt;/code&gt;&lt;/strong&gt; that points &lt;code&gt;main&lt;/code&gt; straight at the Wasm file – no tsconfig, no bundler.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pin the runtime version&lt;/strong&gt; in &lt;code&gt;supabase/config.toml&lt;/code&gt; to avoid accidental upgrades that re‑introduce the V8 bundle step.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;warm‑up&lt;/strong&gt; the function in a CI step (a simple curl) so the first production request sees a hot isolate.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  trade‑offs &amp;amp; edge cases
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;binary size&lt;/strong&gt; – a Rust‑compiled Wasm module can be 300 KB+; that’s fine for edge caches but adds bandwidth on the first fetch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;debugging&lt;/strong&gt; – stack traces are mangled unless you ship source maps (&lt;code&gt;wasm-sourcemap&lt;/code&gt; crate). you lose the quick &lt;code&gt;deno run&lt;/code&gt; dev loop, so keep a parallel TypeScript shim for local testing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;cold‑start mitigation&lt;/strong&gt; vs &lt;strong&gt;cold‑restart cost&lt;/strong&gt; – if you have many function versions, each gets its own cache. a version churn can actually increase overall latency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;runtime limits&lt;/strong&gt; – Supabase caps Wasm memory at 128 MiB. ensure your code stays well under; allocating large buffers will trigger a silent kill.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  what i learned
&lt;/h2&gt;

&lt;p&gt;switching a latency‑critical endpoint from a TypeScript bundle to a single‑file Rust Wasm module shaved ~250 ms off the 99th‑percentile latency. the gain was most noticeable under bursty traffic where Deno isolates spin up in parallel.&lt;/p&gt;




&lt;p&gt;how are you handling cold‑start latency on edge platforms? have you tried a compiled Wasm approach, or do you rely on other warm‑up strategies? share your findings.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>webdev</category>
      <category>architecture</category>
      <category>supabase</category>
    </item>
  </channel>
</rss>
