Wasmer, the versatile WebAssembly runtime, has made significant strides in its integration across various programming languages, including Rust, Python, Ruby, PHP, and Go. In a recent announcement, Ivan Enderlin, a PhD Computer Scientist at Wasmer, unveiled a new Postgres extension version 0.1 for WebAssembly. This innovative extension is currently in active development and is designed to function exclusively with Postgres 10, supporting only integer data types on both 32- and 64-bit architectures. As it stands, the extension does not yet accommodate strings, records, views, or other Postgres types.
Community Engagement and API Development
The official announcement emphasizes the intention to foster a community around this initiative, aiming to collaboratively design a pragmatic API. The goal is to uncover developer expectations and explore how this new technology can be effectively utilized within a database engine. The Postgres extension introduces two foreign data wrappers: wasm.instances and wasm.exported_functions, both residing in the wasm foreign schema.
The wasm.instances table comprises id and wasm_file columns, while the wasm.exported_functions table includes instance_id, name, inputs, and outputs columns. According to Enderlin, this structure provides sufficient information for the Postgres extension to “generate the SQL function to call the WebAssembly exported functions.”
In an effort to assess performance, the Wasmer team conducted a benchmark comparing the execution time of computing the Fibonacci sequence using WebAssembly against PL/pgSQL. This benchmark was executed on a 2016 MacBook Pro 15″ equipped with a 2.9GHz Core i7 processor and 16GB of RAM.
The results indicated that the “Postgres WebAssembly extension is faster to run numeric computations. The WebAssembly approach scales pretty well compared to the PL/pgSQL approach, in this situation.” While the Wasmer team acknowledges that it may be premature to regard WebAssembly as a viable alternative to PL/pgSQL, these findings inspire optimism for further exploration of this technology.
For those interested in delving deeper into the Postgres extension, further details can be found on its GitHub page.