Skip to content

Don't allocate DepNode if anonymous #77070

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

Closed
wants to merge 2 commits into from

Conversation

arora-aman
Copy link
Member

@rust-highfive
Copy link
Contributor

r? @oli-obk

(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 22, 2020
@jonas-schievink
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Collaborator

bors commented Sep 22, 2020

⌛ Trying commit 1888747508e96b9bb9c50679c6d1dec57ce551c4 with merge 5949e52c59d14b10fb338c73e4e37a41bc36131a...

}

// Handled None case above, safe to unwrap here.
let dep_node_index = dep_node_index.unwrap();
Copy link
Member

@bjorn3 bjorn3 Sep 22, 2020

Choose a reason for hiding this comment

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

You can use

let dep_node_index = if let Some(dep_node_index) = dep_node_index {
    dep_node_index
} else {
    return ...
};

Copy link
Member Author

Choose a reason for hiding this comment

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

fair, I'll update once the perf run goes through

@bors
Copy link
Collaborator

bors commented Sep 22, 2020

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

@rust-timer
Copy link
Collaborator

Queued 5949e52c59d14b10fb338c73e4e37a41bc36131a with parent e0bc267, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (5949e52c59d14b10fb338c73e4e37a41bc36131a): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@bjorn3
Copy link
Member

bjorn3 commented Sep 22, 2020

Up to 0.4% slowdown.

@crlf0710
Copy link
Member

crlf0710 commented Oct 8, 2020

Triage: Is this ready for review? There's still [WIP] in the PR title.

@@ -85,6 +85,10 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
fn can_reconstruct_query_key(&self) -> bool {
DepKind::can_reconstruct_query_key(self)
}

fn is_anon(&self) -> bool {
Copy link
Member

@bjorn3 bjorn3 Oct 8, 2020

Choose a reason for hiding this comment

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

Suggested change
fn is_anon(&self) -> bool {
#[inline]
fn is_anon(&self) -> bool {

can_reconstruct_query_key also seems to be missing it. Or maybe it is missing for a reason?

@arora-aman
Copy link
Member Author

Triage: Is this ready for review? There's still [WIP] in the PR title.

@wesleywiser are we planning on merging this change? If so I can push a fixup.

@arora-aman arora-aman changed the title [WIP] Don't allocate DepNode if anonymous Don't allocate DepNode if anonymous Oct 9, 2020
@wesleywiser
Copy link
Member

@arora-aman Don't we still need to do this? #45408 (comment)

I tried building locally and the incremental cache seems to be the same size before and after this change. I would assume we should see some kind of change if the nodes are no longer being allocated.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 23, 2020

r? @wesleywiser

I have no idea what this PR is about 😆

@rust-highfive rust-highfive assigned wesleywiser and unassigned oli-obk Oct 23, 2020
@tgnottingham
Copy link
Contributor

Regarding the overall approach, we can't remove the anonymous nodes without compensating for their removal (most importantly, copying their dependencies up to the things that depend on them). I've made comments on #45408 discussing some of the issues involved. TL;DR, I think the problem to be solved is a bit harder than it first appears, and solving it isn't necessarily a clear win.

Regarding the code, since I suspect the overall approach will change, my comments are probably totally irrelevant in the end. But here they are nonetheless.

  • with_task_impl is supposed to return the allocated node index. If we're not allocating a node, it would be incorrect to say that we were by returning an index. And you wouldn't want to use next_virtual_depnode_index. That's only used when the dep graph is disabled (i.e. non-incremental mode unless some debug options are enabled). If we return that, it'll end up being the index of some other node in the graph most likely.

  • That's all irrelevant though, because that code doesn't ever execute (I'm pretty certain anyway). Anonymous queries are executed using with_anon_task, which doesn't use with_task_impl. In fact, it's probably an error if with_task_impl is called with an anonymous node.

    Given that, it seems appropriate to have finish_task_and_alloc_depnode not return an Option, since the code isn't equipped to handle that case. Callers that create the closure can do the unwrapping of the Option returned by alloc_node. You could also just go back to unwrapping in with_task_impl, but it seems silly to suggest to clients that finish_task_and_alloc_depnode can really return None, when we're just going to panic if it does.

  • The reason you aren't seeing a reduction in size is that anonymous queries use intern_node, not alloc_node. See complete_anon_task.

    That being said, I think it should be using alloc_node. intern_node is used when we think the graph might already contain the node. I don't think that's the case here. I don't think we should be executing the anonymous query if its node is already in the graph. Somewhere higher in the stack, we should have been using the query's cached result.

@wesleywiser
Copy link
Member

Let's go ahead and close this as @arora-aman suggested on Zulip since they're not going to have time to work on this more in the near future.

@arora-aman if want to continue working on this, feel free to re-open at any point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants