5 ms·
The JIT compilation to WebAssembly they are doing with WebVM is pretty cool! I didn't see any benchmarks on the linked to page. I tried their sample Fibonacci
by williamstein 5y ago
The JIT compilation to WebAssembly they are doing with WebVM is pretty cool!
I didn't see any benchmarks on the linked to page. I tried their sample Fibonacci program, but up to 100000 and ONLY timing actual execution (using the time Python module) to not include startup time, and WebVM only took 6.7 times as long as native for me. That's very impressive.
There's a similar open source project called https://copy.sh/v86/ https://copy.sh/v86/. Using their arch Linux image with the exact same Fibonacci benchmark, it take 44 times as long as native.
- syrusakbary 5y agoThanks for the benchmarks! I was curious about timing. Python is also a bit tricky because it does things with pointers that I believe are hard to optimize (or maybe not, who knows!). Have you tried other languages/programs?
- Recursing 5y agoAs a smoke test, I tried running `time python3 -c 'print(max(range(2*10**7)))'` It's about ~10x faster on webvm.io compared to copy.sh/v86 and only ~20x slower than native, impressive stuff
- hughrr 5y ago20x slower than native suggests this solution has its own ozone layer hole.
- benou 5y agoI timed a very simple loop in C: "for (volatile int i=0; i<N; i++);" (handful of arithmetic, compare and branch instructions) with N=1e9 and it was 70% the speed of native which looks really good. I'd love to see LINPACK now :)
- syrusakbary 5y agoThinking more about this. I'd love to try v8 there, so we can benchmark the WebVM v8 against the Native JS in the browser... all using the same engine (is a bit meta, isn't it?)
- apignotti 5y agoWell, nodejs uses V8 and it's installed
- syrusakbary 5y agoExciting... trying it as I type! Edit: I'm trying to run the following benchmarks [1]: function mySlowFunction(baseNumber) { console.time('mySlowFunction'); let result = 0; for (var i = Math.pow(baseNumber, 7); i >= 0; i--) { result += Math.atan(i) * Math.tan(i); }; console.timeEnd('mySlowFunction'); } mySlowFunction(8); // higher number => more iterations => slower Results: 99ms in my Chromium browser (v8 JIT enabled), it breaks in the WebVM (after typing `node` and enter) with `TODO: FAULT af5147bf / CODE da d9 83` Results (not using console time): 99ms in my Chromium browser (v8 JIT enabled), 680ms in WebVM (1050ms in the first run). Conclusion: WebVM node is only 7 times slower than native v8 in my local machine (macOS M1 Max) [1]: https://gist.github.com/sqren/5083d73f184acae0c5b7 https://gist.github.com/sqren/5083d73f184acae0c5b7
- apignotti 5y agoThat's an unimplemented instruction. If I have to make a guess, one the trigonometric funcs you are calling. Feel free to report a bug if you'd like.
- Recursing 5y agoThe issue is triggered by `console.time` Try: function mySlowFunction(baseNumber) { const startTime = Date.now(); let result = 0; for (var i = Math.pow(baseNumber, 7); i >= 0; i--) { result += Math.atan(i) * Math.tan(i); }; console.log(result, 'time:', Date.now() - startTime); } mySlowFunction(8); I get ~100ms in Chromium and ~900ms in the WebVM (if I close the devtools)
- marwis 5y agoIf you want Node in your browser, stackblitz has a super fast implementation. I think it's NodeJS compiled to Wasm but with V8 replaced by browser's native JS engine: https://blog.stackblitz.com/posts/introducing-webcontainers/ https://blog.stackblitz.com/posts/introducing-webcontainers/