-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Various ObligationForest
improvements
#64500
Conversation
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.
ObligationForest
ObligationForest
improvements
I will do a perf run. @bors try |
⌛ Trying commit 4ecd94e with merge b9036784da288d61ad41be8bd937c6d333c7a8bd... |
☀️ Try build successful - checks-azure |
@rust-timer build b9036784da288d61ad41be8bd937c6d333c7a8bd |
Success: Queued b9036784da288d61ad41be8bd937c6d333c7a8bd with parent 3e3e06d, comparison URL. |
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 } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?"
r=me once the benchmarking results are in. |
@nikomatsakis the bench results are already in... :D |
Oh, so they are. @bors r+ |
📌 Commit 4ecd94e has been approved by |
…ikomatsakis Various `ObligationForest` improvements These commits make the code both nicer and faster. r? @nikomatsakis
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
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
|
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>>, |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
More `ObligationForest` improvements Following on from #64500, these commits alsomake the code both nicer and faster. r? @nikomatsakis
These commits make the code both nicer and faster.
r? @nikomatsakis