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

More efficient serialization of struct #65

Open
evmar opened this issue Apr 10, 2024 · 1 comment
Open

More efficient serialization of struct #65

evmar opened this issue Apr 10, 2024 · 1 comment

Comments

@evmar
Copy link

evmar commented Apr 10, 2024

Thanks for making this crate!

I looked into its implementation a bit and have a possible improvement that I discuss here:
https://neugierig.org/software/blog/2024/04/rust-wasm-to-js.html

The tldr is you can avoid the static_str_to_js cache by instead codegenning a JS function per struct that you serialize, which would likely also better this JS VM object construction caches. Some sample code from my prototype sketch. I'm not certain it's possible within the serde architecture -- serde is still a bit overwhelming to me -- but I think maybe it's a small tweak on ObjectSerializer?

In any case, I figured since you were interested in the performance of this area you might be interested in this. Feel free to close this bug if it doesn't suit you, I just figured this was the place to bring it to your attention.

@RReverser
Copy link
Owner

Yeah that would be ideal approach, but it's not possible / compatible with Serde, as it describes all structs at runtime.

The closest you can get is dynamically constructing and caching JS functions via js_sys::Function, but that's its own can of worms and not compatible with all environments.

Ideally static conversion like this should be implemented in wasm-bindgen itself or a separate proc-macro.

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

No branches or pull requests

2 participants