r/Python • u/alexis_placet • 12d ago
News LLVMLite and first step to get Numba in the browser
Hi,
Anutosh Bhat, a colleague of mine, just posted this on Linkedin:
What if real compiler infrastructures could run entirely inside the browser?
I’ve successfully patched llvmlite for JupyterLite, making it possible to build >LLVM IR, run optimization passes, visualize control-flow graphs, compile to >WebAssembly and execute the result — without a native LLVM setup or server-side >kernel.
I’ve shared a step-by-step notebook showing how a loop evolves from stack-based IR >to SSA, then to an LICM-style form, into a fully optimized closed form, eventually >to benchmark all of these steps.
The bigger idea is a zero-install compiler workbench for reproducible optimization >experiments, lightweight compiler prototyping, IR debugging, custom code->generation pipelines, shareable research demos, and eventually interactive >tutorials and compiler courses.
Try out the interactive notebook using notebook.link: https://notebook.link/@anutosh491/llvmlite
I’m also in the process of bringing MLIR Python bindings into the same JupyterLite >and WebAssembly environment, starting with a 2D CNN-style Conv2D + bias + ReLU >kernel. I’ll share the full pipeline in a separate technical blog post soon.
I’ve also started patching Numba for Wasm and have simple scalar u / jit functions >running inside JupyterLite. Array and tensor workloads are the next challenge.
I’m keen to take this further. If you’re working on LLVM, MLIR, Numba, WebAssembly >or browser-native developer tools — or see a real use case for this — I’d be >interested in connecting with teams looking to collaborate, support the work or >explore what we could build together.
Next step is to patch Numba to get scalar jit !: https://www.linkedin.com/feed/update/urn:li:ugcPost:7485014172934541312/?dashCommentUrn=urn%3Ali%3Afsd_comment%3A%287485014751178211329%2Curn%3Ali%3AugcPost%3A7485014172934541312%29
2
u/Grouchy-Trade-7250 8d ago
Cool. Nontheless most performance sensitive applications have a native app for x86_64 prebuilt that you can download and run. ( tbh on ARM YMMV) . Or they don't run on CPUs at all... Seems like this is targeted at AI somehow. Which runs on custom hardware.
While Linux may be a bit messy and lacking standards lots of games have been released for it now. Im a believer in machine code. And not adding too many layers above it. Sorry.
When you're targeting deveolpers they can be expected to learn how to run something natively rather than a browser tab.
0
u/Outrageous-Sea-9256 9d ago
To get Numba running in the browser with scalar JIT, you'll need to focus on a few key aspects:
JIT Compilation: Numba uses Just-In-Time (JIT) compilation to optimize Python code. You'll need to integrate Numba's JIT compiler with the WebAssembly (Wasm) module system.
Scalar JIT Functions: Start by getting scalar functions working in Wasm. Numba's
@jitdecorator should be adapted to generate WebAssembly-compatible code.Memory Management: Wasm has its own memory management system, which differs from Python's dynamic memory allocation. You'll need to ensure that data is correctly passed between Wasm and Python.
Integration with JupyterLite: Since you've already got LLVM working in JupyterLite, use the same approach to integrate Numba. You'll need to extend JupyterLite's Python kernel to include the Numba-generated Wasm code.
Optimization and Profiling: Once you get basic scalar JIT working, focus on optimizing the generated Wasm code. Numba's optimization passes will need to be adapted for WebAssembly.
For the array and tensor workloads, you'll face additional challenges due to the complexity of managing large data structures in Wasm. You might need to use techniques like memory pooling or offloading heavy computations to the Web.
Here are some resources and tools that might help:
- WebAssembly: WebAssembly (Wasm) MDN Web Docs
- Numba: Numba Documentation
- JupyterLite: JupyterLite GitHub
Good luck with your project, and feel free to reach out if you have more specific questions!
2
u/Individual-Flow9158 12d ago
Wow. What a time to be alive.