<?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: m1kc3b</title>
    <description>The latest articles on DEV Community by m1kc3b (@m1kc3b).</description>
    <link>https://dev.to/m1kc3b</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F476074%2Fe34e785b-aee4-4b84-af32-42352a4a8239.png</url>
      <title>DEV Community: m1kc3b</title>
      <link>https://dev.to/m1kc3b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/m1kc3b"/>
    <language>en</language>
    <item>
      <title>🧠 From 2,500 to 1,000,000 Particles: Supercharging a Three.js Demo with WebAssembly</title>
      <dc:creator>m1kc3b</dc:creator>
      <pubDate>Tue, 29 Apr 2025 16:09:34 +0000</pubDate>
      <link>https://dev.to/m1kc3b/from-2500-to-1000000-particles-supercharging-a-threejs-demo-with-webassembly-24b</link>
      <guid>https://dev.to/m1kc3b/from-2500-to-1000000-particles-supercharging-a-threejs-demo-with-webassembly-24b</guid>
      <description>&lt;p&gt;When I first explored the classic &lt;code&gt;webgl_points_waves&lt;/code&gt; demo in Three.js, I was amazed by the simplicity and elegance of the animation — around 2,500 particles oscillating in a wave pattern. But naturally, I wondered: &lt;em&gt;What if we wanted 100× more particles? Could JavaScript handle it?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Spoiler: It can’t. But WebAssembly can.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚧 The Limits of JavaScript in Creative Code
&lt;/h2&gt;

&lt;p&gt;JavaScript is great — but when it comes to realtime simulations involving thousands or millions of calculations per frame, it quickly becomes the bottleneck.&lt;/p&gt;

&lt;p&gt;Tasks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Particle simulations&lt;/li&gt;
&lt;li&gt;Per-frame math on large arrays&lt;/li&gt;
&lt;li&gt;Complex waveforms, physics, or procedural animations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…often demand performance beyond what the JS engine can safely deliver, especially in browsers where garbage collection and dynamic typing introduce runtime overhead.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Rebuilding the Core in Rust
&lt;/h2&gt;

&lt;p&gt;So I rewrote the simulation logic — the part responsible for animating each particle based on time — in Rust, and compiled it to WebAssembly. The rendering still uses Three.js and WebGL, but now the math is done in a much faster, memory-safe native module.&lt;/p&gt;

&lt;p&gt;Without diving into the full code, here's the gist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A buffer of f32 values is allocated and shared with JavaScript&lt;/li&gt;
&lt;li&gt;Each frame, a Rust function updates the Y-position of every particle&lt;/li&gt;
&lt;li&gt;The math involves some trigonometry and time-based modulation (based on sin, cos, and distance to origin)&lt;/li&gt;
&lt;li&gt;Everything is vectorized and runs at near-native speed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In fact, the logic is so efficient that instead of 2,500 particles, we now simulate 1,000,000 — in real time, in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎮 Try It Live
&lt;/h2&gt;

&lt;p&gt;👉 &lt;a href="https://m1kc3b.com/webgl_points_waves_demo" rel="noopener noreferrer"&gt;Demo here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the JS or WASM button and check the FPS counter (top left corner). It’s eye-opening.&lt;/p&gt;

&lt;h2&gt;
  
  
  📦 Under the Hood
&lt;/h2&gt;

&lt;p&gt;The Rust code is compiled with &lt;code&gt;wasm-bindgen&lt;/code&gt;, and exposes a very simple API to JavaScript. Integration is as easy as passing a buffer and a time value to the WASM function — no boilerplate, no complex interop.&lt;/p&gt;

&lt;p&gt;In Rust, everything runs in place, directly on the shared buffer. No allocation, no overhead. That means you get tight control over memory and massive performance gains, especially in repetitive workloads like particle animation.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔥 Why WASM Matters for Creative Developers
&lt;/h2&gt;

&lt;p&gt;This project is more than a performance flex — it's a realistic case study in how WebAssembly can enhance creative web experiences:&lt;/p&gt;

&lt;p&gt;✅ Smooth animations&lt;br&gt;
✅ Clean interop with JS and WebGL&lt;br&gt;
✅ Minimal runtime cost&lt;br&gt;
✅ Scales to millions of data points&lt;/p&gt;

&lt;p&gt;If you're building interactive 3D, simulations, or generative art, WASM is not a nice-to-have — it's a superpower.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 Learn More
&lt;/h2&gt;

&lt;p&gt;For a deeper dive into how I built this and why I think WASM is the future for creative coding, &lt;a href="https://m1kc3b.com/why-wasm" rel="noopener noreferrer"&gt;check out my article&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webgl</category>
      <category>threejs</category>
      <category>webassembly</category>
      <category>rust</category>
    </item>
  </channel>
</rss>
