Live data from Hacker News

Py2wasm – A Python to WASM Compiler

wasmer.io

31–40 of 175 posts

Re: Py2wasm – A Python to WASM Compiler

#31

I want the opposite. The Python VM is everywhere. Can't I just run my WASM on Python? (The WASM runtime must be pure Python, installing C/C++ extensions is against the spirit of this.)

Hmm, what I want is to run WASM using a CPython extension. CPython extensions are vital to Python. I'm curious why you say an extension is against the spirit of it.

Re: Py2wasm – A Python to WASM Compiler

#32

With WasmGC finalized, I hope we see more compilers that target it instead of including their own GC. It's could be a new interpreter, or maybe a version of CPython that uses WasmGC structs for all Python objects, or a compiler similar to this but that targets WasmGC directly.

WasmGC is not really what you think it is. Think of it as a full-on replacement for the linear memory model, not as a way to add GC to it.

It's exceptionally difficult to port a language runtime over to WasmGC -- it doesn't even offer finalizers, so __del__ can't implemented correctly (even ignoring the issues with existing __del__ semantics in Python leading to compatibility issues). It doesn't support interior pointers, so you can't have a pointer into the middle of an array.

There's no easy way to port Python to WasmGC.

Re: Py2wasm – A Python to WASM Compiler

#33
How come the CPython interpreter is so slow when compiled to WebAssembly? According to the figures in the article, it runs at 23% the speed of the native version.

Wasmer, which they're using in the benchmarks, should run code "at near-native speeds" according to the docs[0]. Apparently it has multiple compiler backends, so maybe the choice of backend affects the result?

[0] https://docs.wasmer.io/runtime

Re: Py2wasm – A Python to WASM Compiler

#34
post #29
post #7

> py2wasm converts your Python programs to WebAssembly, running them at 3x faster speeds This is clearly written in the article, but I hope that the impatient readers will understand that this is 3 times faster than the CPython wasm, not the native CPython.

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).

[deleted]

Re: Py2wasm – A Python to WASM Compiler

#35

It may be a stupid question, but is there already some DOM access or a dedicated package that allows writing web applications in this compiled python?

Yes. Here is an example how to integrate Python to React front end https://blog.pyodide.org/posts/react-in-python-with-pyodide/ Similar examples for raw DOM manipulation should be available for Pyodide as well. It has bindings to all JS code, so it can do everything that JS can do.

Thanks. I know about the one for Pyodide. Is it confirmed that it works for this new py2wasm compiler?

Re: Py2wasm – A Python to WASM Compiler

#36
post #29
post #7

> py2wasm converts your Python programs to WebAssembly, running them at 3x faster speeds This is clearly written in the article, but I hope that the impatient readers will understand that this is 3 times faster than the CPython wasm, not the native CPython.

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?

Re: Py2wasm – A Python to WASM Compiler

#38

With WasmGC finalized, I hope we see more compilers that target it instead of including their own GC. It's could be a new interpreter, or maybe a version of CPython that uses WasmGC structs for all Python objects, or a compiler similar to this but that targets WasmGC directly.

Current WasmGC is missing a lot of critical features for production grade GC, like finalization and interior pointers. It's really promising though, so I think once the gaps get filled in you'll see a bunch of runtimes start moving over - maybe .NET, etc.
Post reply on HN