Skip to content

How to cache wasm module in nodejs, or it's already cached on startup ? #37565

Open
@miqbalrr

Description

@miqbalrr

according to this rustwasm/wasm-bindgen#2473

Summary

I created comparison between manual javascript haversine function, and wasm based.
the result if i compared including the module initialization, wasm based getting much slower than javascript itself.

Additional Details

console.time("manual")
const haversinee = require("../func/haversine")
const src = {
    lat: -7.0,
    lng: 7.0
}

const dst = {
    lat: -8.0,
    lng: 8.0
}
console.log("manual js : "+ haversinee(src, dst, false))
console.timeEnd("manual")

console.time("wasm")
const {Point, haversine} = require("haversinecalc") // this is the problem

const src_p = new Point(-7.0,7.0)
const dst_p = new Point(-8.0,8.0)

console.log("using wasm : "+ haversine(src_p, dst_p))
console.timeEnd("wasm")

Result with module initialization included

manual js : 156581.10278754708
manual: 12.337ms
using wasm : 156581.10278754708
wasm: 18.109ms

Result without module initialization

manual js : 156581.10278754708
manual: 7.709ms
using wasm : 156581.10278754708
wasm: 0.287ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasmIssues and PRs related to WebAssembly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions