Breaking the 2GB Barrier: Asynchronous I/O for Large Files in WebAssembly

2025-03-04
Breaking the 2GB Barrier: Asynchronous I/O for Large Files in WebAssembly

The author previously implemented setjmp in WebAssembly, bypassing WASI libc's reliance on the exception handling proposal. However, this approach was limited to files smaller than 2GB. This post details how to use the File API and Blob type to create a memory-based filesystem for handling larger files. Since web I/O is asynchronous while system languages are typically synchronous, Asyncify was used to bridge the paradigms. The author encountered optimization issues with wasm-opt, resolving them by creating a dummy wasm-opt. Finally, by cleverly using a volatile function pointer, they bypassed Asyncify's incorrect assumption about the `asyncjmp_rt_start` function, ultimately achieving asynchronous handling of large files.

Read more
Development File Handling

Compiling Perl to WebAssembly: A Herculean Task

2025-02-11
Compiling Perl to WebAssembly: A Herculean Task

Building a startup, the author faced a challenge: client-side file metadata extraction. ExifTool, while powerful, proved difficult to statically compile and deploy across OSes due to its Perl nature. Various approaches were attempted, including statically compiling Perl, finally leading to WebAssembly. The journey was fraught with challenges, battling Perl's build system, Emscripten, and WASI, even requiring Perl source code modifications. The author successfully built a self-contained WebAssembly Perl running ExifTool, but the process exposed insufficient exception handling support in WebAssembly runtimes.

Read more
Development

Breaking WebAssembly Runtime Limitations: Asyncifying ZeroPerl

2025-02-11
Breaking WebAssembly Runtime Limitations: Asyncifying ZeroPerl

Frustrated by the lack of exnref support in most WebAssembly runtimes, rendering ZeroPerl unusable, the author decided to fix the problem instead of complaining. By leveraging Binaryen's Asyncify feature, a replacement for setjmp was implemented from scratch, bypassing libsetjmp's compatibility issues. After removing the official library, writing assembly code, and optimizing with wasm-opt, ZeroPerl now runs successfully in Wasmer, Wasmtime, and other WebAssembly runtimes. This breakthrough delivers a fully sandboxed and self-contained Perl WebAssembly module.

Read more
Development