Mandelbrot Rust Presentation: FFI to Python and JavaScript (WebAssembly)

In 2020, I was lucky enough to give two presentations on the Rust programming language. The first talk was at Adobe Research, and the second was to the excellent Desert Rust Arizona-based developer group.

The topic of both presentations was to create correct, efficient solutions to problems as a Rust library. Specifically, this library should be designed to be as reusable as possible in other languages, using Rust’s robust FFI facilities. As an example problem, I chose to generate the Mandelbrot set. This problem is a good example for three reasons:

  1. It is highly parallel.
  2. Computing large sets is computationally expensive.
  3. The solution does not have dependencies that break/degrade across the FFI boundary.

Presentation resources

I decided that the best way to convince the audience about the FFI capabilities of Rust was to actually use them. To that end, I created a Mandelbrot set common library in Rust, creatively called mandelbrot_common. This library is published on crates.io, and the source code is published on GitHub.

I then created a Python package which integrated this library, returning the Mandelbrot set as a numpy.ndarray. I accomplished this by using the Rust/Python FFI library PyO3, managed by the maturin package. This package, creatively called mandelbrot_py, is published on pypi.org. The source code is published on GitHub.

I also created a demo Jupyter notebook hosted with the Jupyter Binder service. This notebook allows users to interact with the Python package and view the resulting images.

Finally, I created a tiny web application to render the Mandelbrot set using HTML/JavaScript. This project uses wasm-pack to compile the mandelbrot_common library to WebAssembly. The application is then able to use the mandelbrot_common functionality from JavaScript function calls. This web application is hosted on GitHub Pages. The source code is published on GitHub. The Mandelbrot webapp will also be embedded at the bottom of this page.

The presentation itself

The slides for the presentation are available at:

I do not (currently) have a recorded version of the talk. However, the minutes from the Desert Rust meetup are available at:

The Mandelbrot webapp

Thanks to the magic of iframe, I can directly embed the webapp on this project page. If you’re able to play with the sliders below, then you’re using an application written in Rust and compiled to WebAssembly!

Software Engineer

My interests include Computer Science and Data Visualization.