• Convert to WASM Project

    1 Open
    0 Closed

    cc @pyrate

    This is another project of mine I just 'finished', not directly related to the v2 of the kjv_api, but should provide a much smaller and more manageable introduction into how to write a py2wasm project. I'll update this OP as needed with our resource list and making goals more defined.

    How to currently run this

    1. python -m venv .venv
    2. source .venv/bin/activate
    3. pip install -r requirements.txt
    4. python app.py (a local development server)
    5. open http://127.0.0.1:5000

    What do I mean by "make into a WASM project"

    WASM (WebAssembly) is a standard where a program is compiled into bytecode, which is then compiled to a browser host's native code and run in sort of a virtual machine, in the browser. There are APIs exposed to allow a WebAssembly program to 'do stuff' on the page, interact with files and attached devices. Most programs written in C/C++ can be easily ported via the Emscripten WASM compiler. I have a small amount of experience with C/C++ but have a lot of experience with python. There are many python compilers that will compile python programs into C. py2wasm will take a python program, compile it to C, then will be compiled into WebAssembly, then when downloaded by a visiting client to a website, be compiled into the architecture of the client platform.

    It's rather slow for the user because first it has to download, then compile, then load. There are techniques to make this less annoying for the user, such as loading some content that they need to read/interact with while the WASM is compiling in the background. There's also the consideration that JS wants to work with 'promises' for async - and I don't know how this will work for py2wasm.

    That's why I think this project would be good to experiment with, because adding/changing functionality is easy on account of the small size of the program.

    Resources

    1. The WASM compiler (exposes WASM API): https://emscripten.org/
    2. The python wasm compiler
      1.1. https://wasmer.io/posts/py2wasm-a-python-to-wasm-compiler
      1.2. https://github.com/wasmerio/py2wasm

    Goals

    1. Make a working WASM module from a python program (py2wasm) that just shows an introduction web page with an upload area
    2. Implement the file date checker/git repo commit checker.
    3. Implement the import checker (get imports that are not part of stdlib)
    4. Implement the pypi.org version page parser

    Secondary Goals

    These are for researching features that are desirable in kjv_api_v2 and not needfully integrated into this project. Since this project is pretty simple, using it as a sort of template for

    1. Database management
      0.1 Distributed PostgreSQL (discuss after individual research and mutual understanding of needs for kjv_apiv2 for appropriate type but Multi-Master Asynchronous Replication style might be appropriate)
      0.2 Job queuing system for handling volume of no. 3 below

    2. key/user/group management (for subscribers)
      1.1. Just general experimentation with the best way to manage users and groups. kjv_api_v2 will have to deal with these and there needs to be something easy for the user and easy for management.
      1.2. Payment processing integration with automatic assignment of user keys and group IDs, locking certain features behind the presence of the ID.
      1.3. Key sharing detection and prevention (max-device-per-key limit)

    3. Historical records management for subscribers
      2.1. Local searches and analysis sent to control server for statistics and user ownership retrieval.

    4. Forward files to server for remote processing.
      3.1. Premium feature for subscribers to allow for faster/better quality processing.
      3.2. Expensive operation!

    https://developer.chrome.com/blog/io24-webassembly-webgpu-1