Repository navigation
Meta tracking issue for branch hints (RFC 1131) #26179
Copy link
Copy link
Closed
Labels
A-intrinsicsArea: IntrinsicsArea: IntrinsicsB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.S-tracking-perma-unstableStatus: The feature will stay unstable indefinitely.Status: The feature will stay unstable indefinitely.T-langRelevant to the language teamRelevant to the language teammetabugIssues about issues themselves ("bugs about bugs")Issues about issues themselves ("bugs about bugs")
Description
Tracking and meta discussion for branch and path hinting, including:
likely/unlikelyas accepted in Add an expect intrinsic rfcs#1131 (much has changed since this RFC)core::hint::{likely, unlikely}Tracking Issue forlikely_unlikely#151619core::hint::cold_pathTracking Issue forcold_path#136873bool::select_unpredictableTracking Issue forhint::select_unpredictable#133962#[cold]:
Reacted by ActuallyaDeviloper, Jean-Pierre De Jesus DIAZ, Artem, Peter Blackson, Behnam Esfahbod, Techcable, LunNova, Casey Primozic, james gilles, Ophir LOJKINE and 66 more
Reacted by Gabriel Bjørnager Jensen, Marius Cobzarenco, Haled Odat, Juhan Oskar Hennoste, Matthew Costello and weriomat
Metadata
Metadata
Assignees
Labels
A-intrinsicsArea: IntrinsicsArea: IntrinsicsB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.S-tracking-perma-unstableStatus: The feature will stay unstable indefinitely.Status: The feature will stay unstable indefinitely.T-langRelevant to the language teamRelevant to the language teammetabugIssues about issues themselves ("bugs about bugs")Issues about issues themselves ("bugs about bugs")
Activity
pythonesque commentedon Jun 16, 2015
FWIW, looking through my own code, I actually think the fact that this can't apply to match variants is going to be fairly hard on idiomatic Rust (for example, it means you can't use it when matching on an
Option, which is going to be extremely common since it amounts toif (likely(ptr != NULL))in C).Aatch commentedon Jun 17, 2015
@pythonesque once I get this done, I plan on writing a follow-up RFC for a
#[likely]attribute you can put on match arms. Since it's already possible to put attributes on arms (to support conditional compilation of them), it should be fairly easy to implement.Craig-Macomber commentedon Sep 25, 2015
It might be worth having an "unpredictable" option in addition to likely and unlikely. There is now something to lower it to in LLVM: http://reviews.llvm.org/D12341
apasel422 commentedon Nov 9, 2015
@Aatch Are you still working on this?
vi commentedon Mar 28, 2016
Shall
#[likely]be also on Result?I expect for most code Ok is likely and Err is unlikely. Of course, annotating
iformatchshould override enum variant's annotation.Aatch commentedon Mar 29, 2016
@vi I think hinting should be only be used rarely, so it being on the type doesn't seem like a good idea.
Resultis a bit more general purpose than just error-handling, sot that kind of hinting would impact code where it's inappropriate. Hinting should only really be done at the site itself.vi commentedon Mar 29, 2016
@Aatch, Is it a good idea to have
likelyin every place where something is likely? Can it also serve for self-documentation: follow "likelies" and see happy path?Aatch commentedon Mar 30, 2016
@vi is is not. As a general rule, people are pretty bad at knowing what cases are actually likely or not. Branch hinting is a fairly specific optimisation hint, used incorrectly it can actually make code slower. It should also only really be used when the unlikely case is known to be very unlikely.
Basically, you should only use it if it makes your code faster, otherwise it should be there.
pczarn commentedon Mar 30, 2016
@vi It might be good idea if the likely thing is cheap, and the unlikely thing is expensive. For example,
Vec::pushis expensive if it causes a reallocation, and very cheap otherwise.In my opinion, frequent use of
likelyis either unnecessary or just manual profile-guided optimization.Stebalien commentedon Mar 30, 2016
Instead of arguing about it, why not just test it? Annotate
Result, and then see if rustc bootstraps significantly faster. This won't give a definitive answer but will help determine if it's worth considering.comex commentedon Aug 20, 2016
Now that MIR is a thing, it would be nice if this were implemented.
nikomatsakis commentedon Aug 31, 2016
@comex I do agree =)
@Aatch Not sure what your time is like, but if you don't have time to implement this, it seems like a case where we might be able to mentor someone. The idea would be to leave a comment explaining roughly how you think it should work, and then tagging the issue with
E-mentorandE-help-wanted. I of course can do this too and will try to remember to do so. =)115 remaining items
Change the issue number for `likely_unlikely` and `cold_path`
Change the issue number for `likely_unlikely` and `cold_path`
Rollup merge of rust-lang#133695 - x17jiri:hint_likely, r=Amanieu
Change the issue number for `likely_unlikely` and `cold_path`
Rollup merge of rust-lang#136874 - tgross35:likely-unlikely-tracking,…
Change the issue number for `likely_unlikely` and `cold_path`
Rollup merge of rust-lang#136874 - tgross35:likely-unlikely-tracking,…
Change the issue number for `likely_unlikely` and `cold_path`
Auto merge of #120370 - x17jiri:likely_unlikely_fix, r=saethlin
Auto merge of #120370 - x17jiri:likely_unlikely_fix, r=saethlin
Rollup merge of rust-lang#151576 - tgross35:stabilize-cold-path, r=jh…
Rollup merge of rust-lang#151576 - tgross35:stabilize-cold-path, r=jh…
Rollup merge of rust-lang#151576 - tgross35:stabilize-cold-path, r=jh…
Unrolled build for #151576