Live data from Hacker News

Py2wasm – A Python to WASM Compiler

wasmer.io

171–175 of 175 posts

Re: Py2wasm – A Python to WASM Compiler

#171
post #104
post #40

What's the hello world wasm file size?

ls -lh hello.wasm -rw-r--r--@ 1 tcole staff 24M Apr 22 14:18 hello.wasm This is on macOS. That is hello.py compiled to wasm with Py2wasm.

Indeed, this can be way further optimized. For example, you can probably do a wasm-strip and wasm-opt passes that would leave the wasm file being ~5-10Mb. Still very big, but a bit more reasonable.

The good thing is that thanks to Nuitka you could actually do some tree shaking and only include the imported files and not everything in between (although this might break other behavior such as eval and so).

Re: Py2wasm – A Python to WASM Compiler

#172
post #29

Earlier quoted context omitted.

even more specifically, 3 times faster than wasmer's build of cpython (whatever that is), running on their runtime. i'd be curious to see this benchmark extended, as in my own experience toying with python-like interpreters, you get ~2x slowdown (like their end result) from just compiling to wasm/wasi with clang and running in any 'fast' runtime (e.g. node or wasmtime).

Hey, I'd love to reproduce the ~2x slowdown you commented from running the workload in Native CPython compared to Wasm CPython (in any runtime, browser or outside). Any tip would be helpful so we can debug it. If your claims are accurate, we can easily get py2wasm even running faster than native CPython! Note: we benchmarked in a M3 Max laptop, so maybe there's some difference there?

note that i'm not claiming 2x slowdown for cpython.

but here's one test i've run just now:

using your test file, i've run this one-liner on my x86_64 linux laptop in https://pyodide.org/en/stable/console.html in chromium (v8) and natively (pyodide's urllib doesn't handle https for some reason):

   import requests;exec(requests.get('https://gist.githubusercontent.com/syrusakbary/b318c97aaa8de6e8040fdd5d3995cb7c/raw/1c6cc96cf98bd7bd41c81ba9d10dc4d19b1c3e53/pystone.py').text)
native: ~470k

pyodide: ~200k

i.e. ~2.4x slowdown

Re: Py2wasm – A Python to WASM Compiler

#173
post #172

Earlier quoted context omitted.

Hey, I'd love to reproduce the ~2x slowdown you commented from running the workload in Native CPython compared to Wasm CPython (in any runtime, browser or outside). Any tip would be helpful so we can debug it. If your claims are accurate, we can easily get py2wasm even running faster than native CPython! Note: we benchmarked in a M3 Max laptop, so maybe there's some difference there?

note that i'm not claiming 2x slowdown for cpython. but here's one test i've run just now: using your test file, i've run this one-liner on my x86_64 linux laptop in https://pyodide.org/en/stable/console.html in chromium (v8) and natively (pyodide's urllib doesn't handle https for some reason): import requests;exec(requests.get('https://gist.githubusercontent.com/syrusakbary/b318c97aaa8de6e8040fdd5d3995cb7c/raw/1c6cc…

Thanks!

That should help us a lot to investigate further the difference in timing. I remember trying the py2wasm strategy about 4 years ago, and I got it running faster than native CPython, so there must be something we are missing!

Re: Py2wasm – A Python to WASM Compiler

#174
post #104
post #40

What's the hello world wasm file size?

ls -lh hello.wasm -rw-r--r--@ 1 tcole staff 24M Apr 22 14:18 hello.wasm This is on macOS. That is hello.py compiled to wasm with Py2wasm.

You got it to work? For me it complains about some header files missing and breaks the nuitka installed on the system.

Re: Py2wasm – A Python to WASM Compiler

#175
post #104
post #40

What's the hello world wasm file size?

ls -lh hello.wasm -rw-r--r--@ 1 tcole staff 24M Apr 22 14:18 hello.wasm This is on macOS. That is hello.py compiled to wasm with Py2wasm.

I wonder what's the meaning of doing this , if hello world program need 20M to download before run ?
Post reply on HN