Writing DuckDB extensions in Mojo

Sometimes one needs to combine relational data and multimedia. I wanted to see if I can use DuckDB to process the former and Mojo the latter, all in one integrate solution. It works nicely

Performance wise 300 lines of Mojo tie numpy’s pocketfft single-threaded on the FFT. On 10 cores Mojo scales 4.9× while the equivalent Python UDF gets 2.5.

Mojo 1.0’s lack of module-level globals and placement-init forces a stateless C ABI, which turns out to be why it’s trivially safe to call from every DuckDB worker thread.

The Mojo library is 2MB while numpy alone is over 20MB, if you care about size on disk.

3 Likes