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

JsValue::from_serde is very slow compare to pass string from WASM to js and then using JSON.parse to parse data #2539

Closed
maple-leaf opened this issue Apr 28, 2021 · 2 comments · Fixed by #3031
Labels

Comments

@maple-leaf
Copy link

Summary

JsValue::from_serde is very slow compare to pass string from WASM to js and then using JSON.parse to parse data.

Additional Details

I tried to use 'wasm-bindgen' to test performance of a general senario: request data from server at WASM and then pass data to JS, and find that the JsValue::from_serde is very slow.
And then I change to just pass response text to JS instead, and then using JSON.parse to parse text to json data, which compare to 'from_serde' is way better performance.

So I wanna ask if there's anything I can do to improve from_serde perfroamce?

The perfomrance profile (need to remove extra extension 'txt')

Profile-from_serde_vs_json_parse.json.txt

The performance screenshot
image

And the demo repo to reproduce this issue: https://github.com/maple-leaf/rust-wasm-playgroud

@alexcrichton
Copy link
Contributor

It generally depends on where the time is being spent. If the time is being spent copying the data into wasm's linear memory, that's unfortunately pretty difficult. If the time is spent in JSON parsing itself then you could consider parsing in JS and then passing pieces to wasm so you don't copy all of the data. Unfortunately though I don't have time myself to dig into this and provide more help at this time.

@RReverser
Copy link
Member

You might want to use serde-wasm-bindgen instead which avoids JSON parsing / serialization. Also see tracking issue and previous discussion in #1258.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants