You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reduced performance when using question mark operator instead of try! #37939
This was reported on the users forum , and I don't want it to get lost. Basically, replacing try! by ? resulted in ~20% performance loss in benchmarks:
@arielb1 I've implemented a test version of the "variant copy prop" by hacking into CopyPropagation. However @eddyb has unfortunately 😉 said that it's much better to make a more general version of that that can propagate copies of aggregates (somehow).
You can still provoke it to make a difference and introduce conditionals or more copies for the ? operator than for the try!() macro if you change the payload types for the Result, for example using (i32, i32) or String.
According to this blog post, Rust has to this date (Rust 1.62.1) performance problems with the question mark operator, resulting in a 4% performance loss.
EDIT: I opened #100693 to have a codegen test here.
Reacted by Jonathan Tran, Vinzent Steinberg, Jakub Beránek, Kornel, runiq, Jonas Platte, Quentin Perez, Nicholas, Julien Coulombe, memoryruins and 3 more
Activity
arthurprs commentedon Nov 24, 2016
I didn't read the implementation until now, I though they expanded to the exact same thing as try!()
sfackler commentedon Nov 24, 2016
Might just need to stick a couple of
#[inline]s onCarriermethods.StefanoD commentedon Nov 26, 2016
I'm curious why this issue doesn't even get a label like I-Slow.
birkenfeld commentedon Dec 3, 2016
@sfackler I tried this (
#[inline]on the trait method definitions and the impl methods), but didn't seem to get any different bench numbers.bluss commentedon Dec 11, 2016
@arielb1 I've implemented a test version of the "variant copy prop" by hacking into CopyPropagation. However @eddyb has unfortunately 😉 said that it's much better to make a more general version of that that can propagate copies of aggregates (somehow).
improve build_index performance by 5-10%
Rollup merge of rust-lang#42275 - scottmcm:try-trait, r=nikomatsakis
Rollup merge of rust-lang#42275 - scottmcm:try-trait, r=nikomatsakis
kdy1 commentedon Sep 28, 2017
I think this issue is fixed.
Generated asm is same for try! and ?.
https://play.rust-lang.org/?gist=625d88df305ace951a088e1cee2ec13a
Edit: Typo
StefanoD commentedon Sep 28, 2017
Even if this is fixed: Is there a unit test which prevents regression?
kennytm commentedon Sep 28, 2017
We could have a
codegentest for this.Someone tag this as
E-needstestplease...5 remaining items
arielb1 commentedon Feb 1, 2018
@mati865
I know that. It has a bug that I couldn't quite pin out.
kornelski commentedon Apr 24, 2018
Still not fixed (tested nightly on playpen)
https://play.rust-lang.org/?version=nightly&mode=release&edition=2015&gist=b3858efebcadbffcbe2155e3f2750d07
mehcode commentedon Aug 31, 2018
This seems to be fixed (in stable). Tried the play link above.
bluss commentedon Dec 1, 2018
You can still provoke it to make a difference and introduce conditionals or more copies for the
?operator than for thetry!()macro if you change the payload types for theResult, for example using(i32, i32)orString.mati865 commentedon Apr 3, 2019
Looks like it regressed: https://godbolt.org/z/awKD_U
mati865 commentedon Aug 17, 2022
We are fast again (at least for the examples given above) since Rust 1.52 which contains LLVM 12 upgrade!
Once somebody adds test (or confirms that similar test already exists) this issue could be closed.
Kobzol commentedon Aug 17, 2022
There's this codegen test, but I'm not sure if it's enough to check for this.
StefanoD commentedon Aug 17, 2022
According to this blog post, Rust has to this date (Rust 1.62.1) performance problems with the question mark operator, resulting in a 4% performance loss.
scottmcm commentedon Aug 17, 2022
Definitely not -- you'll notice it's both
-Zunsound-mir-optsandFIXME: broken.But there's good news! LLVM 15 merged a few days ago, bringing the fix mentioned in #85133 (comment).
With that, both of these are nops now:
https://rust.godbolt.org/z/71dYnrMf6
For comparison, on 1.63 even the
matchversion needs a bunch of code: https://rust.godbolt.org/z/oarec37sGEDIT: I opened #100693 to have a codegen test here.
JohnTitor commentedon Dec 21, 2022
Triage: #100693 added the test for this case (thank you @scottmcm!), closing as fixed.