js-compute-runtime icon indicating copy to clipboard operation
js-compute-runtime copied to clipboard

js-compute-runtime is non-hermetic

Open thesayyn opened this issue 9 months ago • 2 comments

Based on my experiments building javascript into .wasm via js-compute-runtime command is non-repeatable and non-deterministic.

Simply running js-compute-runtime src dest twice yields different results even though the source is unchanged.

This is problem when building things with Bazel due to unstable outputs affecting cache hit rates.

Reproducer; Get diffoscope from here: https://diffoscope.org/

js-compute-runtime a.js  1.wasm
js-compute-runtime a.js  2.wasm


diiffoscope 1.wasm 2.wasm

thesayyn avatar Apr 13 '25 18:04 thesayyn

I wasn't able to track where this non-determinism comes from, but my educated guess is rustc.

thesayyn avatar Apr 13 '25 18:04 thesayyn

installing wasm2wat gives a better insight as to why this is happening; i see a bunch of non-stable constants.

-  (data (;8756;) (i32.const 5557032) "$\01")
-  (data (;8757;) (i32.const 5557064) "\d0\00\00\00\00\00\00\00\d1\00\00\00\00\00\00\00M\01\00\00\00\00\00\00\d1")
-  (data (;8758;) (i32.const 5557112) "u2\00\00\00\00\00\00$\01")
+  (data (;8756;) (i32.const 5557032) "w\01")
+  (data (;8757;) (i32.const 5557064) "\d0\00\00\00\00\00\00\00\fa\00\00\00\00\00\00\00$\01\00\00\00\00\00\00\d0")
+  (data (;8758;) (i32.const 5557112) "\1b3\00\00\00\00\00\00w\01")

thesayyn avatar Apr 13 '25 18:04 thesayyn