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

Various ObligationForest improvements #64500

Merged
merged 11 commits into from
Sep 17, 2019

Conversation

nnethercote
Copy link
Contributor

These commits make the code both nicer and faster.

r? @nikomatsakis

Those with type `usize` are now called `i`, those with type `NodeIndex`
are called `index`.
This commit removes the custom index implementation of `NodeIndex`,
which probably predates `newtype_index!`.

As well as eliminating code, it improves the debugging experience,
because the custom implementation had the property of being incremented
by 1 (so it could use `NonZeroU32`), which was incredibly confusing if
you didn't expect it.

For some reason, I also had to remove an `unsafe` block marker from
`from_u32_unchecked()` that the compiler said was now unnecessary.
These refer to code that no longer exists.
This makes the code a little faster, presumably because bounds checks
aren't needed on `nodes` accesses. It requires making `scratch` a
`RefCell`, which is not unreasonable.
It's more concise, more idiomatic, and measurably faster.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 16, 2019
@nnethercote nnethercote changed the title Various ObligationForest Various ObligationForest improvements Sep 16, 2019
@nnethercote
Copy link
Contributor Author

I will do a perf run.

@bors try

@bors
Copy link
Contributor

bors commented Sep 16, 2019

⌛ Trying commit 4ecd94e with merge b9036784da288d61ad41be8bd937c6d333c7a8bd...

@bors
Copy link
Contributor

bors commented Sep 16, 2019

☀️ Try build successful - checks-azure
Build commit: b9036784da288d61ad41be8bd937c6d333c7a8bd

@Centril
Copy link
Contributor

Centril commented Sep 16, 2019

@rust-timer build b9036784da288d61ad41be8bd937c6d333c7a8bd

@rust-timer
Copy link
Collaborator

Success: Queued b9036784da288d61ad41be8bd937c6d333c7a8bd with parent 3e3e06d, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit b9036784da288d61ad41be8bd937c6d333c7a8bd, comparison URL.

@@ -149,7 +149,7 @@ macro_rules! newtype_index {

#[inline]
$v const unsafe fn from_u32_unchecked(value: u32) -> Self {
unsafe { $type { private: value } }
$type { private: value }
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not needed because the function itself is unsafe, so it's allowed to have unsafe operations in the body

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. The obvious follow-up question is "why didn't the compiler complain about this before?"

@nikomatsakis
Copy link
Contributor

r=me once the benchmarking results are in.

@Centril
Copy link
Contributor

Centril commented Sep 16, 2019

@nikomatsakis the bench results are already in... :D

@nikomatsakis
Copy link
Contributor

Oh, so they are.

@bors r+

@bors
Copy link
Contributor

bors commented Sep 16, 2019

📌 Commit 4ecd94e has been approved by nikomatsakis

@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 Sep 16, 2019
Centril added a commit to Centril/rust that referenced this pull request Sep 17, 2019
…ikomatsakis

Various `ObligationForest` improvements

These commits make the code both nicer and faster.

r? @nikomatsakis
bors added a commit that referenced this pull request Sep 17, 2019
Rollup of 6 pull requests

Successful merges:

 - #64085 (Tweak unsatisfied HRTB errors)
 - #64380 (Update bundled OpenSSL to 1.1.1d)
 - #64416 (Various refactorings to clean up nll diagnostics)
 - #64500 (Various `ObligationForest` improvements)
 - #64530 (Elide lifetimes in `Pin<&(mut) Self>`)
 - #64531 (Use shorthand syntax in the self parameter of methods of Pin)

Failed merges:

r? @ghost
@nnethercote
Copy link
Contributor Author

Thank you for the fast review.

BTW, this code can be very hot and parts of it are very perf-sensitive to change. Here is a list of other ways I tried to speed up or clean up ObligationForest, but failed:

  • Inline and remove insert_into_error_cache again(); caused slow-downs even when that code wasn't executed, presumably due to different inlining?
  • Use std::usize::MAX to indicate nodes to be removed; caused slow-downs.
  • Use IndexVec<Node<O>> for nodes; caused slow-downs.
  • Use drain_filter() for dependents in apply_rewrites(); caused slow-downs.
  • Use drain_filter() in compress; couldn't get past the borrow checker.
  • Make process_obligation() iterate over new nodes added to nodes; caused infinite loops.
  • Split nodes in two, to reduce the number of bytes copied by the shuffling in compress(); didn't finish, felt too invasive and likely to cause slow-downs.
  • Use swap_and_remove() to reduce the number of bytes copied by the shuffling in `compress(); caused slow-downs.
  • Box everything in Node; caused slow-downs.
  • Box everything in Node except state: caused slow-downs

@bors bors merged commit 4ecd94e into rust-lang:master Sep 17, 2019
@nnethercote nnethercote deleted the ObligForest-fixups branch September 17, 2019 05:25
bors added a commit that referenced this pull request Sep 17, 2019
More `ObligationForest` improvements

Following on from #64500, these commits alsomake the code both nicer and faster.

r? @nikomatsakis
scratch: Option<Vec<usize>>,
/// A scratch vector reused in various operations, to avoid allocating new
/// vectors.
scratch: RefCell<Vec<usize>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this can be replaced with Cell, which is simpler and panic-free, as you are only calling .replace on this (i.e. not utilizing "Ref" functionality).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip. I will do it in a follow-up.

bors added a commit that referenced this pull request Sep 19, 2019
More `ObligationForest` improvements

Following on from #64500, these commits alsomake the code both nicer and faster.

r? @nikomatsakis
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.

7 participants