JavaScript’s Number type is a float64 and is limited to 53 bits of actual value (as specified by IEEE 754).
Wasm offers a 64 bits integer type, there’s currently no efficient way to represent this type in JavaScript, which can be limiting.
JavaScript recently introduced the BigInt object, allowing the representation of arbitrary length integers.
The BigInt interpretation inevitably introduce an overhead, however the conversions happen only at the JavaScript boundaries. The i64 is then used directly in Wasm, which has no overhead.
You can see the CL I made here: https://chromium-review.googlesource.com/c/v8/v8/+/1355144.
Note that, currently it's only supported when:
--experimental-wasm-bigint
flag to v8.A SpiderMonkey (Firefox) is also work-in-progress.
(module
(func export 'fn') (result i64)
(i64.const 66)
)
)
exports.fn().constructor
===
exports.fn()
===
(module
(func (export 'fn') (param i64) (result i64)
(get_local 0)
)
)
exports.fn(0n)
===
exports.fn(-0n)
===
exports.fn(123n)
===
exports.fn(-123n)
===