Skip to content
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

Avoid creating SmallVecs in global_llvm_features #97579

Merged
merged 1 commit into from
Jun 6, 2022

Conversation

SparrowLii
Copy link
Member

@SparrowLii SparrowLii commented May 31, 2022

This PR made a simple optimization to avoid creating extra SmallVecs by adjusting the use of iterator statements.
Also, given the very small size of tied_target_features, there is no need to insert each feature into the FxHashMap.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 31, 2022
@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2022
Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement to readability! See nits inline though.

@@ -218,6 +218,9 @@ pub fn check_tied_features(
sess: &Session,
features: &FxHashMap<&str, bool>,
) -> Option<&'static [&'static str]> {
if features.len() == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is probably better written as something like:

if !features.is_empty() {
    for tied in ... {
        ...
    }
}
return None;

The code isn't particularly deeply nested here and avoids having to specify None as a return twice.

@@ -485,35 +490,35 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
}
diag.emit();
}
Some((enable_disable, feature))

if diagnostics && tied_features.iter().any(|tied| tied.contains(&feature)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing a second linear lookup through the tied_features list (in addition to the one that will happen later in the check_tied_features.

Ignoring entirely the fact that what's going on here is an exercise in micro-optimization, and the overall performance of the compiler is likely going to stay pretty much the same, I feel like such double lookup is probably defeating any improvements gained here by all the other changes.

It would seem to me that we'd be better off by just not checking this here (while leaving everything else intact):

Suggested change
if diagnostics && tied_features.iter().any(|tied| tied.contains(&feature)) {
if diagnostics {

Copy link
Member Author

@SparrowLii SparrowLii Jun 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out! That makes sense and I think we can keep the FIXME here

@nagisa nagisa added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2022
@SparrowLii
Copy link
Member Author

Thanks for reviewing! I made the corresponding corrections

@nagisa
Copy link
Member

nagisa commented Jun 6, 2022

@bors r+ thanks!

@bors
Copy link
Contributor

bors commented Jun 6, 2022

📌 Commit b3cd892 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 6, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 6, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97312 (Compute lifetimes in scope at diagnostic time)
 - rust-lang#97495 (Add E0788 for improper #[no_coverage] usage)
 - rust-lang#97579 (Avoid creating `SmallVec`s in `global_llvm_features`)
 - rust-lang#97767 (interpret: do not claim UB until we looked more into variadic functions)
 - rust-lang#97787 (E0432: rust 2018 -> rust 2018 or later    in --explain message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6da214c into rust-lang:master Jun 6, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants