-
-
Notifications
You must be signed in to change notification settings - Fork 779
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
Use ?
instead of try!
internally and in generated code
#2366
Comments
The last time I checked (~1 year ago) |
Surprising but fair enough. |
Supposedly this was fixed last August: rust-lang/rust#37939 |
Oh nice. I think that issue was only in regard to runtime performance though? I tried to check compile time using this diff in serde_derive: macro_rules! try {
(#dollar __expr:expr) => {
- match #dollar __expr {
- _serde::__private::Ok(__val) => __val,
- _serde::__private::Err(__err) => {
- return _serde::__private::Err(__err);
- }
- }
+ #dollar __expr?
}
} and using the following commands:
and these all compile consistently 6.5–7.5% slower on my machine with The gap would be larger upon using Maybe the gap would be slightly smaller with I did confirm the json-benchmark produces an identical binary after strip, so that's great. I could believe it no longer makes sense to use |
?
instead of try!
internally and in generated code?
instead of try!
internally and in generated code
Much of serde's implementation uses
try!
, which I assumed was for backwards compatibility reasons. However, while support forOption
was only added in Rust 1.22, the?
itself was added in Rust 1.13, a much earlier version than serde's claimed MSRV of 1.19.I'd need to bench to be sure, but my presumption is that
?
, a built-in operator, is faster for the compiler than expanding thetry!
macro.The text was updated successfully, but these errors were encountered: