-
-
Notifications
You must be signed in to change notification settings - Fork 785
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
Deserializing untagged enums is slow #2101
Comments
Another solution is to not use untagged enum and implement deserialization manually. However I wonder what is the exact use case of untagged enums in |
This was caught in my benchmarks for general APIs reading For a general API, you also have to deal with values being one of several types, for example key_to_string = "value"
key_to_num = 200 As for And yes, another solution is the "do nothing". The challenge with that is this is surprisingly, embarrassingly slow and doesn't meet with the general expectation for serde's performance. |
Ah, OK, I was under the impression that optimizing for |
This previously came up in #748. My preference is that this be explored in a different crate with a |
Should we at least have some note in the documentation for untagged? |
As an update on this, serde-untagged was recently created to make hand-implementing the derive easier. In rust-lang/cargo#12574, I forgot about this conversation and brought up the idea of this being supported natively in dtolnay said
@dtolnay are you thinking that this might be re-opened or do you still lean on this being experimented on outside of |
Currently there is a moratorium on new attributes to keep serde_derive compile time under control. |
Would a PR for the untagged documentation that discusses the trade offs and calls out |
Yes -- thanks! I am not sure what to say about the serde-untagged yet since I am rewriting erased-serde at the moment; after that I will have a better idea of what the guidance should be. |
When profiling toml_edit, a hand-written
Deserialize
for an untagged enum took a benchmark for a common case in cargo from 484us to 181us (for a singleCargo.toml
file, using this in the dependency resolving would multiple that by hundreds).Root Cause
The derive's untagged enum implementation tries each variant, one after another.
For each failure, we generate an error which allocates its message and is adverised as a
#[cold]
Potential Solutions
invalid_type
invalid_type
#[cold]
(I'm assuming this will make little difference)The text was updated successfully, but these errors were encountered: