Skip to content

Specialize merge_attrs in good case #76782

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

Merged
merged 1 commit into from
Sep 18, 2020
Merged

Specialize merge_attrs in good case #76782

merged 1 commit into from
Sep 18, 2020

Conversation

tesuji
Copy link
Contributor

@tesuji tesuji commented Sep 16, 2020

Just a non-important micro-optimization.
r? @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 16, 2020
@jyn514 jyn514 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 16, 2020
@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-compiletime Issue: Problems and improvements with respect to compile times. 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 Sep 16, 2020
Comment on lines 310 to 320
// NOTE: If we have additional attributes (from a re-export),
// always insert them first. This ensure that re-export
// doc comments show up before the original doc comments
// when we render them.
if let Some(a) = other_attrs {
merged_attrs.extend(a.iter().cloned());
if let Some(inner) = other_attrs {
merged_attrs = inner.to_vec();
}
merged_attrs.extend(attrs.to_vec());
merged_attrs.extend_from_slice(attrs);
merged_attrs.clean(cx)
Copy link
Member

@jyn514 jyn514 Sep 17, 2020

Choose a reason for hiding this comment

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

Ok, what about this idea, which preserve the order and never performs an unnecessary copy:

    let merged_attrs = if let Some(inner) = other_attrs {
        let mut both_attrs = inner.to_vec();
        both_attrs.extend_from_slice(attrs);
        both_attrs
    } else {
        attrs.to_vec()
    };

Copy link
Member

Choose a reason for hiding this comment

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

The reason I want to push for this is because it's very rare to have additional documentation on a re-export, but very common to have a lot of documentation on the original item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it has much different since Vec::new has cap=0.
Also, your and my code reallocates when other_attrs is_some, IIUC.

Copy link
Member

Choose a reason for hiding this comment

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

One reallocation is really cheap though, it's only reallocation in a loop that's slow (which this doesn't do).

@jyn514
Copy link
Member

jyn514 commented Sep 18, 2020

I'm curious to see whether the perf difference is noticable.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Collaborator

bors commented Sep 18, 2020

⌛ Trying commit 2818032 with merge 45d9a0fe6bdb703dac3cc60690e84de52ab6cf6d...

@tesuji tesuji changed the title Calculate more correct capacity in merge_attrs Specialize merge_attrs in good case Sep 18, 2020
@bors
Copy link
Collaborator

bors commented Sep 18, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 45d9a0fe6bdb703dac3cc60690e84de52ab6cf6d (45d9a0fe6bdb703dac3cc60690e84de52ab6cf6d)

@rust-timer
Copy link
Collaborator

Queued 45d9a0fe6bdb703dac3cc60690e84de52ab6cf6d with parent f3c923a, future comparison URL.

@jyn514 jyn514 added S-waiting-on-perf Status: Waiting on a perf run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 18, 2020
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (45d9a0fe6bdb703dac3cc60690e84de52ab6cf6d): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@jyn514
Copy link
Member

jyn514 commented Sep 18, 2020

Mostly noise, that's about what I expected. max-rss went down quite a bit, but not on doc runs (??) so it must be noise too.

Well, this code is still better than before.

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 18, 2020

📌 Commit 2818032 has been approved by jyn514

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 18, 2020
@bors
Copy link
Collaborator

bors commented Sep 18, 2020

⌛ Testing commit 2818032 with merge bbc6774...

@bors
Copy link
Collaborator

bors commented Sep 18, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: jyn514
Pushing bbc6774 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 18, 2020
@bors bors merged commit bbc6774 into rust-lang:master Sep 18, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 18, 2020
@tesuji tesuji deleted the rd-cap branch September 19, 2020 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-compiletime Issue: Problems and improvements with respect to compile times. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-perf Status: Waiting on a perf run to be completed. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants