Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda