Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Why are JS / React much quicker than WebAssembly / Rust?

I'm doing some tests with Wasm generated by Rust (wasm_bindgen). What dazzles me is that the JavaScript implementation seems to be much quicker than the Rust implementation.

The program is creating n items of a dict / object / map and pushing it to an array.

The JavaScript implementation is very easy:

const createJSObjects = (amount: number) => {
  const arr: Array<{ index: number }> = []
  for (let i = 0; i < amount; i++) {
    arr.push({
      index: i
    })
  }
  return arr
}

easy enough. The Rust implementation is similar:

#[wasm_bindgen]
pub fn create_rust_objects(amount: usize) -> JsValue {
    let mut arr: Vec<Obj> = vec![];
    arr.reserve(amount);

    for i in 0..amount {
        let itm = Obj { index: i };
        arr.push(itm);
    }

    JsValue::from_serde(&arr).unwrap()
}

I've also tried with a vector of hashmaps:

let mut field = HashMap::new();
field.insert("index", i);
arr.push(field);

Both are equally "slow".

I'm importing the Wasm binary with the generated js and d.ts files that comes with the wasm-build.

The JavaScript is at least twice as fast as the rust code. Why is this? Am I doing something wrong with the implementation? The implementation is set up according to MDN docs.

I've put all the code in a React project - https://github.com/Devalo/rust-react-wasm-test

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The answer is that you are likely not doing anything wrong. Essentially, WASM has the potential to be faster, but will not always be faster.

I really liked this quick read from Winston Chen in which they run performance testing comparing web assembly to vanilla JS.

If you're interested in more in-depth conversation, this talk by Surma at Google I/O '19 is very informative. From the video:

Both JavaScript and Web Assembly have the same peak performance. They are equally fast. But it is much easier to stay on the fast path with Web Assembly than it is with JavaScript.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!