Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way buffers are passed to the wasm-node #396

Merged
merged 5 commits into from
Apr 6, 2023

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Apr 6, 2023

Close #375

This PR modifies the way the JS passes buffers to the Rust.
Instead of calling an alloc function to allocate memory in the Wasm, the JS now locally assigns a "buffer index", and the Rust uses host functions in order to obtain the properties of each "buffer index".

This makes things more simple, and also fixes a potential undefined behavior.

One small wart is that the connection_new function (JS function called by the Rust) requires allocating a buffer index that can only be freed "some time in the future" rather than at a determinate point in time.
However, this is in practice not a problem given that buffer index 0 is constantly written over.

@github-actions
Copy link

github-actions bot commented Apr 6, 2023

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        +851 ┊ <futures_util::stream::unfold::Unfold<T,F,Fut> as futures_core::stream::Stream>::poll_next::h697290eadcad6e9c
        -851 ┊ <futures_util::stream::unfold::Unfold<T,F,Fut> as futures_core::stream::Stream>::poll_next::he5c66c7ba77a43a2
        +205 ┊ add_chain
        -132 ┊ futures_util::unfold_state::UnfoldState<T,R>::take_value::h9babf0fa52cb7d6d
        +132 ┊ futures_util::unfold_state::UnfoldState<T,R>::take_value::ha1e5107e3a5bd3ee
        +102 ┊ alloc::raw_vec::RawVec<T,A>::allocate_in::hd536446d9776dbed
        +100 ┊ smoldot_light_wasm::bindings::get_buffer::haeb6592cf46700cc
         +98 ┊ futures_util::unfold_state::_::<impl futures_util::unfold_state::UnfoldState<T,R>>::project_replace::h3e44ab8dea30ccc7
         -98 ┊ futures_util::unfold_state::_::<impl futures_util::unfold_state::UnfoldState<T,R>>::project_replace::he55c536e1f12eada
         -94 ┊ alloc
         -93 ┊ core::result::Result<T,E>::unwrap::h96ab1208f15e76e6
         +80 ┊ data[0]
         -79 ┊ core::array::<impl core::ops::index::Index<I> for [T; N]>::index::h553e97ecd944e4cb
         +73 ┊ futures_util::unfold_state::UnfoldState<T,R>::project_future::h17016c0b103031fe
         -73 ┊ futures_util::unfold_state::UnfoldState<T,R>::project_future::h3c8f854c79006575
         -71 ┊ <smoldot_light_wasm::platform::Platform as smoldot_light::platform::Platform>::connect::h13c215900d2e995e
         +67 ┊ stream_message
         +63 ┊ connection_reset
         +59 ┊ core::ptr::drop_in_place<futures_util::unfold_state::UnfoldState<smoldot_light::JsonRpcResponses,smoldot_light_wasm::add_chain::{{closure}}::{{closure}}::{{closure}}>>::h1172919e8188cfbf
         -59 ┊ core::ptr::drop_in_place<futures_util::unfold_state::UnfoldState<smoldot_light::JsonRpcResponses,smoldot_light_wasm::add_chain::{{closure}}::{{closure}}::{{closure}}>>::h5721b0538a646ba3
         +39 ┊ ... and 41 more.
        +282 ┊ Σ [61 Total Rows]

@tomaka tomaka added this pull request to the merge queue Apr 6, 2023
Merged via the queue into smol-dot:main with commit e10dda4 Apr 6, 2023
@tomaka tomaka deleted the fix-375 branch April 6, 2023 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rethink the alloc function of the wasm bindings
1 participant