from Hacker News

Py2wasm – A Python to WASM Compiler

by fock on 4/22/24, 2:10 PM with 49 comments

  • by wdroz on 4/22/24, 2:51 PM

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

  • by boomskats on 4/22/24, 3:19 PM

    So I had a look at the repo/branches at https://github.com/wasmerio/py2wasm. This might be a nit, but in the spirit of OSS: if I'd done this work, I'd have contributed it to upstream Nuitka. I definitely would not have forked a whole new GitHub repo and given it a completely different name.

    What's the rationale for creating a new project and calling it py2wasm? Am I missing something?

  • by ubj on 4/22/24, 2:41 PM

    Nice--it's great to see more options for interoperability between Python and WASM. I was aware of Pyodide [1], but Py2wasm seems to be a tool for compiling specific scripts into WASM rather than having an entire Python distribution in the browser. Please correct me if I'm misunderstanding the difference between the two however.

    [1]: https://pyodide.org/en/stable/

  • by umvi on 4/22/24, 8:08 PM

    What's up with the botspam in this thread? Looks like hundreds of sex bot accounts are being created. Pages seem really slow to load currently... someone should notify dang.
  • by ptx on 4/22/24, 4:32 PM

    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

  • by spankalee on 4/22/24, 4:00 PM

    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.

  • by grondilu on 4/22/24, 2:29 PM

    Nice. Maybe a pie in the sky but considering how prevalent python is in machine learning, how likely is it that at some point most ML frameworks written in python become executable on a web browser through WASM?
  • by theanonymousone on 4/22/24, 3:24 PM

    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?
  • by vimota on 4/22/24, 10:21 PM

    > We worked on py2wasm to fulfill our own needs first, as we want to accelerate Python execution to the maximum, so we can move our Python Django backend from Google Cloud into Wasmer Edge.

    I was under the impression that Django was stateful and not meant to be run in a serverless/edge cloud. Is that not the case or are you planning to do a special setup to support that?

  • by weinzierl on 4/22/24, 4:07 PM

    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.)
  • by lenerdenator on 4/22/24, 5:54 PM

    Would it be too late to call it PyToWasm?

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

  • by lagt_t on 4/22/24, 7:13 PM

    What's the hello world wasm file size?
  • by spxneo on 4/22/24, 6:52 PM

    so does this mean we can run FastAPI inside a browser?