IssueRaiser

Splitting into multiple lazily-loaded modules

### Motivation See motivation here: https://github.com/rustwasm/team/issues/52 ### Proposed Solution I have implemented a (limited/hacky) prototype, based on the following components: - A `#[wasm_split(xyz)]` function attribute macro that serves to annotate a function as a *split point*. `xyz` is an identifier for the module that this function should be "split off" into. The same identifier can be used multiple times, in which case multiple functions will be "split off" into the same module. In my prototype the function must be non-async, and this macro turns it into an async function, but it wouldn't be hard to support both sync and async split points. For example, the macro converts: ```rust #[wasm_split(zstd)] fn get_zstd_decoder( encoded_reader: Pin<Box<dyn futures::io::AsyncBufRead>>, ) -> Pin<Box<dyn futures::io::AsyncRead>> { Box::pin(async_compression::futures::bufread::ZstdDecoder::new( encoded_reader, )) } ``` into ```rust async fn get_zstd_decoder( __wasm_split_arg_0: Pin<Box<dyn futures::io::AsyncBufRead>>, ) -> Pin<Box<dyn futures::io::AsyncRead>> { thread_local! { static ::wasm_split::LazySplitLoader> = unsafe { ::wasm_split::LazySplitLoader::new(__wasm_split_load_zstd) }; } #[link(wasm_import_module = "./__wasm_split.js")] extern "C" { #[no_mangle] fn __wasm_split_load_zstd( callback: unsafe extern "C" fn(*const ::std::ffi::c_void, bool), data: *const ::std::ffi::

Posted by jbms on Apr 27, 2024, 8:08 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments

ux (Software)

Splitting into multiple lazily-loaded modules

jbmsApr 27, 2024, 8:08 PM

### Motivation See motivation here: https://github.com/rustwasm/team/issues/52 ### Proposed Solution I have implemented a (limited/hacky) prototype, based on the following components: - A `#[wasm_split(xyz)]` function attribute macro that serves to annotate a function as a *split point*. `xyz` is an identifier for the module that this function should be "split off" into. The same identifier can be used multiple times, in which case multiple functions will be "split off" into the same module. In my prototype the function must be non-async, and this macro turns it into an async function, but it wouldn't be hard to support both sync and async split points. For example, the macro converts: ```rust #[wasm_split(zstd)] fn get_zstd_decoder( encoded_reader: Pin<Box<dyn futures::io::AsyncBufRead>>, ) -> Pin<Box<dyn futures::io::AsyncRead>> { Box::pin(async_compression::futures::bufread::ZstdDecoder::new( encoded_reader, )) } ``` into ```rust async fn get_zstd_decoder( __wasm_split_arg_0: Pin<Box<dyn futures::io::AsyncBufRead>>, ) -> Pin<Box<dyn futures::io::AsyncRead>> { thread_local! { static ::wasm_split::LazySplitLoader> = unsafe { ::wasm_split::LazySplitLoader::new(__wasm_split_load_zstd) }; } #[link(wasm_import_module = "./__wasm_split.js")] extern "C" { #[no_mangle] fn __wasm_split_load_zstd( callback: unsafe extern "C" fn(*const ::std::ffi::c_void, bool), data: *const ::std::ffi::

Comments (0)

No comments yet. Start the discussion.

Comment on this issue