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

optimize NLL constraint propagation a little #49472

Merged
merged 5 commits into from
Mar 31, 2018

Conversation

nikomatsakis
Copy link
Contributor

Removes a bone-headed hot spot in NLL constant propagation; we were re-allocating the stack vector and hashmap as we repeated the DFS. This change shares those resources across each call.

It also modifies the constraint list to be a linked list; arguably I should revert that, though, as this didn't turn out to be a perf hit and perhaps the old code was clearer? (Still, the new style appeals to me.)

r? @pnkfelix

@nikomatsakis nikomatsakis force-pushed the nll-optimize-constraint-prop-1 branch from a8a09b4 to 8144c8f Compare March 29, 2018 07:45
@Mark-Simulacrum
Copy link
Member

@bors try

@@ -34,25 +51,29 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// - `Ok(false)` if the walk was completed with no changes;
/// - `Err(early)` if the walk was existed early by `op`. `earlyelem` is the
/// value that `op` returned.
pub(super) fn dfs<C>(&self, mir: &Mir<'tcx>, mut op: C) -> Result<bool, C::Early>
#[inline(never)] // ensure dfs is identifiable in profiles
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep this in? Seems potentially bad for performance, though it does seem somewhat unlikely.

Copy link
Member

@pnkfelix pnkfelix Mar 29, 2018

Choose a reason for hiding this comment

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

(removed comment from review that was intended as response to @Mark-Simulacrum above)

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 believe this would ever be criticial for performance, this is why I kept it in, but for sure it is not relevant now, given the data we're looking at. =) And it's convenient for profiling etc.

@bors
Copy link
Contributor

bors commented Mar 29, 2018

⌛ Trying commit 8144c8f with merge 288ea68...

bors added a commit that referenced this pull request Mar 29, 2018
…=<try>

optimize NLL constraint propagation a little

Removes a bone-headed hot spot in NLL constant propagation; we were re-allocating the stack vector and hashmap as we repeated the DFS. This change shares those resources across each call.

It also modifies the constraint list to be a linked list; arguably I should revert that, though, as this didn't turn out to be a perf hit and perhaps the old code was clearer? (Still, the new style appeals to me.)

r? @pnkfelix
@@ -539,7 +587,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
for type_test in &self.type_tests {
debug!("check_type_test: {:?}", type_test);

if self.eval_region_test(mir, type_test.point, type_test.lower_bound, &type_test.test) {
if self.eval_region_test(mir, dfs_storage, type_test.point, type_test.lower_bound, &type_test.test) {
Copy link
Member

Choose a reason for hiding this comment

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

[00:05:33] tidy error: /checkout/src/librustc_mir/borrow_check/nll/region_infer/mod.rs:590: line longer than 100 chars
[00:05:34] some tidy checks failed

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 29, 2018
Copy link
Member

@pnkfelix pnkfelix left a comment

Choose a reason for hiding this comment

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

r=me after you've addressed the nits.

@@ -34,25 +51,29 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// - `Ok(false)` if the walk was completed with no changes;
/// - `Err(early)` if the walk was existed early by `op`. `earlyelem` is the
/// value that `op` returned.
pub(super) fn dfs<C>(&self, mir: &Mir<'tcx>, mut op: C) -> Result<bool, C::Early>
#[inline(never)] // ensure dfs is identifiable in profiles
Copy link
Member

@pnkfelix pnkfelix Mar 29, 2018

Choose a reason for hiding this comment

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

(removed comment from review that was intended as response to @Mark-Simulacrum above)

@@ -143,10 +148,22 @@ pub struct Constraint {
/// At this location.
point: Location,

/// Later on, we thread the constraints onto a linked list
/// sorted by their `sub` field. So if you had:
Copy link
Member

Choose a reason for hiding this comment

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

The use of the word "sort" in this comment confused me: "There's a single list and its sorted by the sub field? Or there's a bunch of lists and each is individually sorted by the sub field -- but how is there any kind of sort order here?"

I usually treat the term "sort" as meaning "make an ordered sequence"; but here you mean it more as "group together (via a linked list) all of the constraints that have the same sub field."

@@ -403,10 +422,23 @@ impl<'tcx> RegionInferenceContext<'tcx> {
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
mir: &Mir<'tcx>,
mir_def_id: DefId,
) -> Option<ClosureRegionRequirements<'gcx>> {
common::time(infcx.tcx.sess, &format!("solve({:?})", mir_def_id), || {
Copy link
Member

Choose a reason for hiding this comment

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

Consider using something a little more specific than just "solve" here, like "solve region constraints", just to ease lives of other users of -Z time-passes

@bors
Copy link
Contributor

bors commented Mar 29, 2018

☀️ Test successful - status-travis
State: approved= try=True

@nikomatsakis
Copy link
Contributor Author

@Mark-Simulacrum try run succeeded, were you gonna do a perf run?

@Mark-Simulacrum
Copy link
Member

Totally forgot, but I've started it now. We can land without too, I don't particularly care.

@nikomatsakis nikomatsakis force-pushed the nll-optimize-constraint-prop-1 branch from 551d512 to ca8176d Compare March 29, 2018 17:32
@nikomatsakis
Copy link
Contributor Author

@bors r=pnkfelix

@bors
Copy link
Contributor

bors commented Mar 29, 2018

📌 Commit ca8176d has been approved by pnkfelix

@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 Mar 29, 2018
@nikomatsakis
Copy link
Contributor Author

nikomatsakis commented Mar 29, 2018

@Mark-Simulacrum as usual, I am unable to construct a working URL :(

This is what I tried:

http://perf.rust-lang.org/compare.html?start=288ea682772125d25d7c076ba0b7d87584da1189&end=409744bcb91f4efa35b8fcc9e7033523a86b90c2&stat=instructions:u

But I know it's gonna' be faster.

UPDATE: Oh, hey, it works now! But I got the order of the revisions backward. Try this:

http://perf.rust-lang.org/compare.html?start=409744bcb91f4efa35b8fcc9e7033523a86b90c2&end=288ea682772125d25d7c076ba0b7d87584da1189&stat=instructions:u

@bors
Copy link
Contributor

bors commented Mar 31, 2018

⌛ Testing commit ca8176d with merge 3c5f850...

bors added a commit that referenced this pull request Mar 31, 2018
…=pnkfelix

optimize NLL constraint propagation a little

Removes a bone-headed hot spot in NLL constant propagation; we were re-allocating the stack vector and hashmap as we repeated the DFS. This change shares those resources across each call.

It also modifies the constraint list to be a linked list; arguably I should revert that, though, as this didn't turn out to be a perf hit and perhaps the old code was clearer? (Still, the new style appeals to me.)

r? @pnkfelix
@bors
Copy link
Contributor

bors commented Mar 31, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: pnkfelix
Pushing 3c5f850 to master...

@bors bors merged commit ca8176d into rust-lang:master Mar 31, 2018
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.

5 participants