⚡
EINCODE
>Home>Projects>Workbench>Blog
GitHubTwitterLinkedIn
status: building
>Home>Projects>Workbench>Blog
status: building

Connect

Let's build something together

Always interested in collaborations, interesting problems, and conversations about code, design, and everything in between.

send a signal→

Find me elsewhere

GitHub
@ehsanghaffar
Twitter
@ehsanghaffar
LinkedIn
/in/ehsanghaffar
Email
hello@ehsanghaffar.dev
Forged with& code

© 2026 EINCODE — All experiments reserved

back to blog
systems

Rust + WebAssembly Performance Deep Dive

Benchmarking Rust compiled to WebAssembly vs native JavaScript. When does WASM shine and when to stick with JS?

EG

Ehsan Ghaffar

2024-09-1811 min read
#rust#wasm#performance

The Performance Question

WebAssembly promises near-native performance in the browser. But is it always faster than JavaScript? Let's find out with real benchmarks.

Test Setup

We'll compare three scenarios:

  1. Pure JavaScript
  2. Rust compiled to WASM
  3. Rust WASM with JS interop

Benchmark 1: Fibonacci (CPU-bound)

// Rust
#[wasm_bindgen]
pub fn fibonacci(n: u32) -> u32 {
    match n {
        0 => 0,
        1 => 1,
        _ => fibonacci(n - 1) + fibonacci(n - 2)
    }
}
// JavaScript
function fibonacci(n) {
  if (n <= 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

Results (fib(40), 100 iterations):

  • JavaScript: 1,245ms
  • Rust WASM: 892ms
  • WASM wins by 28%

Benchmark 2: Array Processing

Processing 1M elements with map/reduce operations.

Results:

  • JavaScript: 45ms
  • Rust WASM: 52ms (with copy overhead)
  • Rust WASM SharedArrayBuffer: 23ms
  • WASM wins only with shared memory

When to Use WASM

Use WASM for:

  • Heavy computation (image processing, cryptography)
  • Games and simulations
  • Porting existing C/C++/Rust codebases

Stick with JS for:

  • DOM manipulation
  • Light data processing
  • When bundle size matters

Conclusion

WASM isn't a silver bullet. The overhead of crossing the JS-WASM boundary can negate performance gains for small operations. Profile first, optimize second.

share
share:
[RELATED_POSTS]

Continue Reading

systems

Building a Linux Distro from Scratch

A comprehensive guide to compiling the kernel, configuring BusyBox, and creating bootable ISOs with Syslinux. Learn the fundamentals of Linux system architecture.

2025-11-15•12 min read