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.)
Py2wasm – A Python to WASM Compiler
31–40 of 175 posts
Re: Py2wasm – A Python to WASM Compiler
#32With 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.
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
#33Wasmer, 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?
Re: Py2wasm – A Python to WASM Compiler
#34> 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).
Re: Py2wasm – A Python to WASM Compiler
#35It 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.
Re: Py2wasm – A Python to WASM Compiler
#36> 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).
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
#37I know Python 2 has been EOL for over four years now but you still see it (much to the chagrin of decent engineers everywhere) in the wild; could generate confusion.
Re: Py2wasm – A Python to WASM Compiler
#38With 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.