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

Shrink ParamEnv to 16 bytes #73978

Merged
merged 2 commits into from
Jul 7, 2020
Merged

Conversation

Mark-Simulacrum
Copy link
Member

r? @nnethercote

x.py check passes but I haven't tried running perf or tests

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 3, 2020
@Mark-Simulacrum
Copy link
Member Author

@bors try @rust-timer queue

I personally suspect that the overhead on access may erase some of the wins here, but it's unclear -- depends on if we copy the values around more or access the fields more, I guess.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 3, 2020

⌛ Trying commit 11c802b024d95e2a9d88c4a204046367b1352286 with merge a5a9f964fe2e8c2722d433ff27446ff72bdd4cff...

@bors
Copy link
Contributor

bors commented Jul 3, 2020

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

@rust-timer
Copy link
Collaborator

Queued a5a9f964fe2e8c2722d433ff27446ff72bdd4cff with parent 3503f56, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (a5a9f964fe2e8c2722d433ff27446ff72bdd4cff): comparison url.

@Mark-Simulacrum
Copy link
Member Author

Looks like some reasonable wins. Adjusted the Hash impl to avoid pulling out the pointer and enum separately, just hashing the pointer directly, let's see if that helps improve the wins here a bit more.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 3, 2020

⌛ Trying commit d6f2554111681111a745df0d90dd4029a1174a81 with merge 7f6d689a6a0a19aa8873a1034c27b49f859521e0...

@bors
Copy link
Contributor

bors commented Jul 3, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 7f6d689a6a0a19aa8873a1034c27b49f859521e0 (7f6d689a6a0a19aa8873a1034c27b49f859521e0)

@rust-timer
Copy link
Collaborator

Queued 7f6d689a6a0a19aa8873a1034c27b49f859521e0 with parent f844ea1, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (7f6d689a6a0a19aa8873a1034c27b49f859521e0): comparison url.

@Mark-Simulacrum Mark-Simulacrum force-pushed the shrink-paramenv branch 2 times, most recently from 007e820 to ffcbbe5 Compare July 3, 2020 22:12
@Mark-Simulacrum
Copy link
Member Author

Looks like changing the Hash impl had roughly zero effect, which is not unexpected (hashing one extra byte was unlikely to really contribute any time), but seems like a reasonable thing to do regardless.

I've polished up the code a bit; I think this is ready for review. It seems like perf shows (very) slight wins across the board. This is also likely to be a memory usage win, though that's not really showing up in our max-rss (unsurprisingly).

r? @nnethercote

Copy link
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! r=me once the nits are addressed.

pub struct ParamEnv<'tcx> {
// We pack the caller_bounds List pointer and a Reveal enum into this usize, relying
// on the List<ty::Predicate<'tcx>> type having at least 2-byte alignment.
// List's start with a usize and are repr(C) so this should be fine; there
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: no apostrophe.

src/librustc_middle/ty/mod.rs Show resolved Hide resolved
pub struct ParamEnv<'tcx> {
// We pack the caller_bounds List pointer and a Reveal enum into this usize, relying
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: explain more clearly what the packing is, i.e. the low bit is the reveal (where 0 means UserFacing and 1 means All) and the rest is the pointer (which works because of the > 2-byte alignment).

packed_data: packed_data
| match reveal {
Reveal::All => 1,
Reveal::UserFacing => 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: swap these arms so the 0 is first?

@Mark-Simulacrum
Copy link
Member Author

@bors r=nnethercote rollup=never (due to perf effect)

@bors
Copy link
Contributor

bors commented Jul 5, 2020

📌 Commit 8512d2e has been approved by nnethercote

@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 Jul 5, 2020
@Manishearth
Copy link
Member

@bors p=1

@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 Jul 6, 2020
@bors
Copy link
Contributor

bors commented Jul 6, 2020

⌛ Testing commit 8512d2e with merge 708f84e70f4726600b2dd3ce23b58dbf6cb98274...

@bors
Copy link
Contributor

bors commented Jul 6, 2020

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 6, 2020
@Mark-Simulacrum
Copy link
Member Author

Seems like a legitimate timeout, but I don't really think this PR could be causing it, so let's @bors retry - timeout (mingw) again.

cc @pietroalbini

@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 Jul 6, 2020
@bors
Copy link
Contributor

bors commented Jul 6, 2020

⌛ Testing commit 8512d2e with merge c18e7b14eb1d045a640c926c3d6dfda5faeceb98...

@Manishearth
Copy link
Member

@bors retry yield

@tmiasko
Copy link
Contributor

tmiasko commented Jul 6, 2020

Unfortunately timeouts on Azure are now common occurrence (usually with one of Windows jobs taking build above the time limit):

ci

@Manishearth
Copy link
Member

Yes, i've noticed the bors build timing out a lot more often :/

@bors
Copy link
Contributor

bors commented Jul 6, 2020

⌛ Testing commit 8512d2e with merge 8981dbb...

@mati865
Copy link
Contributor

mati865 commented Jul 6, 2020

@bors
Copy link
Contributor

bors commented Jul 7, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: nnethercote
Pushing 8981dbb to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 7, 2020
@bors bors merged commit 8981dbb into rust-lang:master Jul 7, 2020
@nnethercote
Copy link
Contributor

This was a perf win, as expected. Nice work!

flip1995 pushed a commit to flip1995/rust that referenced this pull request Jul 14, 2020
…ethercote

Shrink ParamEnv to 16 bytes

r? @nnethercote

x.py check passes but I haven't tried running perf or tests
Comment on lines +1579 to +1589
// We pack the caller_bounds List pointer and a Reveal enum into this usize.
// Specifically, the low bit represents Reveal, with 0 meaning `UserFacing`
// and 1 meaning `All`. The rest is the pointer.
//
// This relies on the List<ty::Predicate<'tcx>> type having at least 2-byte
// alignment. Lists start with a usize and are repr(C) so this should be
// fine; there is a debug_assert in the constructor as well.
//
// Note that the choice of 0 for UserFacing is intentional -- since it is the
// first variant in Reveal this means that joining the pointer is a simple `or`.
packed_data: usize,
Copy link
Member

Choose a reason for hiding this comment

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

Late to the party, but maybe move all of the safety-critical parts of this into a ty::param_env module? That or we could try to build a bit-packed abstraction (since ty::GenericArg does something similar), or look for one on crates.io and audit it.

@Mark-Simulacrum Mark-Simulacrum deleted the shrink-paramenv branch July 16, 2020 14:45
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 18, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 18, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 18, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 19, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 19, 2020
@cuviper cuviper added this to the 1.46 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants