-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 serde support shouldn't go through serde_json #1258
Comments
I'm currently working on a generic solution for this to improve performance of one of my projects. Is it possible to assign this issue to me for tracking? |
@RReverser go for it! :) |
So far it looks like more often than not perf is actually getting worse due to overhead of frequent calls between JS and WASM (at least on Node.js / V8). But I just finished the prototype, and only starting to actually profile and see what could be improved, so still hoping for something obvious. P.S. This is where I found the |
Okay, after a bunch of custom improvements and, finally, #1391, I've finally managed to surpass serde_json in terms of benchmark performance (this turned out way harder than it seemed at first). Now time to focus on cleaning up and trying to reduce the size :) |
Hey @RReverser is there somewhere I can see your work on writing the serde (de)serializers? They sound awesome! |
It's effectively ready (feature-complete), but I'm trying to use it in our real internal app (Cloudflare Worker) before open-sourcing. Should be out soon! |
Okay, file-size savings of WASM+Brotli look promising now too (used against benchmarks which parse/serialize a bunch of structures with either one or the other library):
Getting there! |
Okay, I've finally published a wasm-bindgen + Serde integration as a separate library - https://github.com/cloudflare/serde-wasm-bindgen. There are few reasons for that at the moment. First, it makes it's a bit easier to maintain that way as it has own tests, benchmarks and stability guarantees which we might want to play with over time. Another, more important, issue is that, in order to support more JavaScript types and idiomatic conversions, it's not strictly compatible with current If that's okay, I'd love to eventually replace Serde support in wasm-bindgen to use I suppose this will require waiting for a breaking change release? If so, it might be worth just pointing users to the external crate in docs for now, and eventually either switching or removing current wasm-bindgen Either way, I hope that's okay and solves the issue, and let me know what you think about further integration! |
Nice!!
It isn't clear to me if this is a theoretical incompatibility of encoding into JS values potentially in the future or if it is already incompatible in practice right now. If the latter, do you have examples of Rust things that serialize into different JS values right now? I agree that incompatibly changing the JS value encoding would require a breaking bump, since people could have JS code they interact with that very reasonably depends on the shape of the JS values returned from something that uses the current
Agreed. We can also put a notice on the current methods and docs linking to this new external crate right now. I think this kind of functionality is fundamental enough that we want to include it "built-in" to wasm-bindgen, so I would prefer to swap out our current |
On compatibility matters: I have in mind situations where I want to share code between server and client, e.g. for an isomorphic web app, or for an API library that could be running in a straight Rust or a JS-interop environment. The same code might therefore expect to be emitting JSON on the server, or interacting with JavaScript values on the client; incompatibility between the two would therefore be very undesirable. The current use of serde_json has the incidental benefit of guaranteeing compatibility. |
I agree. As said above, though, my concern is coupling between versions - we might want to experiment with supported types in serde-wasm-bindgen in the future. When these are separate independent crates, it's pretty easy for users to bump one without the other, but when it's built-in, now we need to be much more careful about breaking changes since bumping wasm-bindgen to major upgrades seems more rare... What do you think?
Few things off the top of my mind:
|
@fitzgen Would you like to make a PR for this? If not, I might, but you might be better with wording :) |
I suspect that by the time we are ready to do a breaking change in
Sure, I can whip a draft up. |
Sounds reasonable to me. Just been thinking about an overall design and coupling, but if it's okay with you, fine by me too :)
Thanks! |
PR to add a note to the guide: #1553 |
This |
Going through
serde_json
ends up including a bunch off64
formatting code, which is quite code size heavy.I'm not super familiar with implementing serde serializers and deserializers, but if we can express "we only support things that can
AsRef<JsValue>
" as a trait bound for serialization, then I think we can go directly into and fromJsValue
without stringifying. This could be a perf win as well.The text was updated successfully, but these errors were encountered: