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.

Development File Handling