|
| 1 | +#### Overview |
| 2 | + |
| 3 | +[Numba](https://numba.pydata.org/) is the standard |
| 4 | +just-in-time (JIT) compiler for numerical Python, widely used |
| 5 | +across the scientific stack to accelerate compute-heavy code. |
| 6 | +Until recently it could not run in the browser: its JIT |
| 7 | +backend, [llvmlite](https://github.com/numba/llvmlite), relies |
| 8 | +on execution engines that WebAssembly does not provide. |
| 9 | + |
| 10 | +We have made Numba work in the browser. Numba and llvmlite now |
| 11 | +run inside [JupyterLite](https://jupyterlite.readthedocs.io/), |
| 12 | +compiling Python functions to WebAssembly and executing them in |
| 13 | +the same page, with no server involved. We are looking for |
| 14 | +funding to turn this prototype into a capability the ecosystem |
| 15 | +can rely on, maintained upstream in Numba and llvmlite. |
| 16 | + |
| 17 | +See our announcement, |
| 18 | +[Numba in the Browser](https://notebook.link/blog/numba-in-the-browser/), |
| 19 | +for the full story. |
| 20 | + |
| 21 | +#### What Works Today |
| 22 | + |
| 23 | +- llvmlite runs in the browser, through a WebAssembly execution |
| 24 | + engine that emits WebAssembly objects from LLVM IR, links them |
| 25 | + in-process with LLVM's linker LLD, and loads each result as an |
| 26 | + Emscripten side module. |
| 27 | +- Numba's `@jit` and `@njit` compile and execute inside a |
| 28 | + JupyterLite kernel, on arrays as well as scalars. |
| 29 | +- Packages that depend on Numba run in the browser, including |
| 30 | + [PyTensor](https://github.com/pymc-devs/pytensor), |
| 31 | + [PyMC](https://github.com/pymc-devs/pymc), |
| 32 | + [Dolo.py](https://github.com/EconForge/dolo.py) and |
| 33 | + [interpolation.py](https://github.com/EconForge/interpolation.py). |
| 34 | +- On the example in our announcement, Numba gives a roughly |
| 35 | + 250x speedup in WebAssembly, against about 90x for the same |
| 36 | + code natively. |
| 37 | + |
| 38 | +#### Why Numba in the Browser Matters |
| 39 | + |
| 40 | +A substantial part of the scientific Python stack depends on |
| 41 | +Numba, frequently as a hard requirement rather than an optional |
| 42 | +accelerator. PyTensor, PyMC, QuantEcon, stumpy and others are in |
| 43 | +this category. Until now none of them could be installed in |
| 44 | +Pyodide or emscripten-forge at all: not a matter of running |
| 45 | +slower in the browser, but of not running. |
| 46 | + |
| 47 | +Numba also covers a case that pre-compiled extensions |
| 48 | +structurally cannot. Code written interactively in a notebook |
| 49 | +does not exist until the user types it, so it cannot be shipped |
| 50 | +ahead of time in a wheel or a conda package. A JIT compiler is |
| 51 | +the only way to make that code fast, and notebooks are precisely |
| 52 | +where browser-based Python is used. |
| 53 | + |
| 54 | +#### Why QuantStack |
| 55 | + |
| 56 | +QuantStack has in-house Numba expertise, which is rare, combined |
| 57 | +with long experience of LLVM in WebAssembly. We develop |
| 58 | +[xeus-cpp](https://github.com/jupyter-xeus/xeus-cpp), a C++ |
| 59 | +interpreter running in the browser via Clang and LLVM compiled |
| 60 | +to WebAssembly, and the execution engine behind Numba in the |
| 61 | +browser grew directly out of that work. We also maintain |
| 62 | +[emscripten-forge](https://github.com/emscripten-forge) and are |
| 63 | +core contributors to Jupyter and JupyterLite, where this work is |
| 64 | +deployed. |
| 65 | + |
| 66 | +#### Proposed Work |
| 67 | + |
| 68 | +The prototype establishes the end-to-end architecture. Making it |
| 69 | +dependable means: |
| 70 | + |
| 71 | +- upstreaming the llvmlite and Numba changes as focused, |
| 72 | + reviewable contributions; |
| 73 | +- expanding test coverage, running the llvmlite and Numba test |
| 74 | + suites in the browser; |
| 75 | +- improving compilation performance and adding persistent |
| 76 | + caching, so that compiled functions survive a page reload; |
| 77 | +- validating and packaging more of the Numba ecosystem for |
| 78 | + emscripten-forge. |
| 79 | + |
| 80 | +These are separable pieces of work: we advance incrementally and |
| 81 | +deliver sub-parts, so the project can be funded in full or in |
| 82 | +part. |
| 83 | + |
| 84 | +##### Are you interested in this project? Either entirely or partially, contact us for more information on how to help us fund it. |
0 commit comments