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

Use MaybeUninit in libcore #54668

Merged
merged 7 commits into from
Nov 27, 2018
Merged

Use MaybeUninit in libcore #54668

merged 7 commits into from
Nov 27, 2018

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Sep 29, 2018

All code by @japaric. This re-submits the second half of #53508 (the first half is at #54667). This is likely the one containing the perf regression.

@rust-highfive
Copy link
Collaborator

r? @dtolnay

(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 Sep 29, 2018
@RalfJung
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Sep 29, 2018

⌛ Trying commit 5f7792bf46e67c5e2277dbf3644e4ba5b34fac0f with merge 5e4ca24261a1348f3242d6885c8a286182b958b2...

@kennytm kennytm added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 29, 2018
@RalfJung RalfJung force-pushed the use-maybe-uninit branch 2 times, most recently from b80c934 to e51b814 Compare September 29, 2018 15:08
@RalfJung
Copy link
Member Author

(Looks like try is done but there was no notification about that? @rust-lang/infra )

@rust-timer build 5e4ca24261a1348f3242d6885c8a286182b958b2

@RalfJung

This comment has been minimized.

@rust-timer

This comment has been minimized.

@RalfJung
Copy link
Member Author

@rust-timer build 5e4ca24261a1348f3242d6885c8a286182b958b2

(And there is no good way to copy-paste the commit SHA in one step)

@rust-timer
Copy link
Collaborator

Success: Queued 5e4ca24261a1348f3242d6885c8a286182b958b2 with parent 7e7bc06, comparison URL.

@dtolnay
Copy link
Member

dtolnay commented Sep 29, 2018

r? @RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned dtolnay Sep 29, 2018
@RalfJung
Copy link
Member Author

@dtolnay Eh, I submitted this. I do not think I should review it.^^

@dtolnay
Copy link
Member

dtolnay commented Sep 29, 2018

You already reviewed this code in #53508. Please clarify what remains to be reviewed.

Assigning the same reviewer as #54667:
r? @cramertj

@rust-highfive rust-highfive assigned cramertj and unassigned RalfJung Sep 29, 2018
@RalfJung
Copy link
Member Author

I wasn't aware of a policy for re-submissions of reverted PRs that would let me r+ this even though I assembled the commits.

And anyway I expect this PR will need changes because there will be perf regressions. But let's see.

@kennytm kennytm removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 30, 2018
@Valinora
Copy link

Perf results are in, this definitely looks to be the source of the regression.

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 2, 2018

@RalfJung I don't know if this helps, but I don't see anything suspicious with this PR, so maybe the issue causing the regression is not here?

One "suspicious" thing is that the regression happens in liballoc, but MaybeUninit is declared in libcore and its methods are not #[inline], which means that they cannot reliably be inlined into other crates without some form of LTO. The functions being touched here are big, so maybe LTO is not inlining these?

If you look at the disassembly of these tests and see a call instruction pointing to the MaybeUninit methods in libcore, it might be worth testing whether making MaybeUninit methods #[inline] might fix this regression.

@RalfJung
Copy link
Member Author

RalfJung commented Oct 2, 2018

It's methods are generic though so #[inline] shouldn't make a difference, right?

the regression happens in liballoc

Where are you getting that from?

Unfortunately I will not have much time to work on this this week.

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 2, 2018

It's methods are generic though so #[inline] shouldn't make a difference, right?

Indeed. The only way in which that could make a difference is if they call a non-generic function that is not #[inline], but it appears that this is not the case. I'm out of ideas.

Where are you getting that from?

I thought most of the changes here were in liballoc, but there are some changes in libcore as well. It might be worth it to figure out which of the changes (slice rotate, slice sort, ptr, liballoc's btree, etc.) introduces the regression.

@RalfJung
Copy link
Member Author

RalfJung commented Oct 8, 2018

I might be doing the wrong thing, but I failed to reproduce the perf regression... in fact, issue-46449 got 12% faster with this PR in my measurement:

$ hyperfine -w 1 -m 3 -p 'rm target -rf' 'cargo +stage1 build --release' 'cargo +stage1.2 build --release'
Benchmark #1: cargo +stage1 build --release

  Time (mean ± σ):      3.532 s ±  0.014 s    [User: 6.576 s, System: 0.115 s]
 
  Range (min … max):    3.520 s …  3.548 s
 
Benchmark #2: cargo +stage1.2 build --release

  Time (mean ± σ):      3.166 s ±  0.059 s    [User: 6.180 s, System: 0.137 s]
 
  Range (min … max):    3.122 s …  3.233 s
 
Summary

  'cargo +stage1.2 build --release' ran
    1.12x faster than 'cargo +stage1 build --release'

@ogoffart
Copy link
Contributor

Keep in mind that if this is happening in cargo check testcases, all you'll be seeing is how fast or slow rustc is, with LLVM not being involed at all.

If I read the number correctly, the "-check" benchmark does not seem to be impacted. The red numbers are only in the "-opt" and "-debug" benchmarks

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 4fe0b8e11185e30d88ba5f5060aadf25b5236ea0

kennytm added a commit to kennytm/rust that referenced this pull request Nov 23, 2018
Fix invalid bitcast taking bool out of a union represented as a scalar

As reported in rust-lang#54668 (comment)
Code by @japaric, I just split it into individual commits
Code by @japaric, I just split it into individual commits
Code by @japaric, I just split it into individual commits
Code by @japaric, I just split it into individual commits
Code by @japaric, I just split it into individual commits
Code by @japaric, I just split it into individual commits
@RalfJung RalfJung added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 23, 2018
@RalfJung
Copy link
Member Author

Unions got fixed, I rebased this PR.

So, can we land this?

Copy link
Contributor

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

(I'm in no position to review, but i see no problem with this, and since it is required to stabilize MaybeUnitit, it'd be great to have it in as early as possible)

@SimonSapin
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 26, 2018

📌 Commit 59786b0 has been approved by SimonSapin

@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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2018
@bors
Copy link
Contributor

bors commented Nov 26, 2018

⌛ Testing commit 59786b0 with merge 75d937c...

bors added a commit that referenced this pull request Nov 26, 2018
Use MaybeUninit in libcore

All code by @japaric. This re-submits the second half of #53508 (the first half is at #54667). This is likely the one containing the perf regression.
@bors
Copy link
Contributor

bors commented Nov 27, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: SimonSapin
Pushing 75d937c to master...

@bors bors merged commit 59786b0 into rust-lang:master Nov 27, 2018
@gnzlbg
Copy link
Contributor

gnzlbg commented Nov 27, 2018

Finally, awesome, thanks!

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.