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

Improve RuleGraph convergence time slightly #10700

Merged
merged 3 commits into from Sep 1, 2020

Conversation

stuhood
Copy link
Sponsor Member

@stuhood stuhood commented Aug 28, 2020

Problem

One of the open issues in https://www.pantsbuild.org/v2.0/docs/internal-rules-architecture was that we weren't able to prune based on transitive information.

Solution

Track whether the in_set of a node is transitively minimal, which allows us to prune nodes that don't consume a provided Param sooner. Additionally, document some of the other things I've explored recently, and add a minimal testcase that goes into an infinite loop without the splits special case.

Result

This does not fix #10683 unfortunately. Still on it.

@coveralls
Copy link

coveralls commented Aug 28, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling 592db7b on stuhood:stuhood/rule-graph-converge into 2fc8a42 on pantsbuild:master.

@stuhood stuhood force-pushed the stuhood/rule-graph-converge branch from 34ba70b to 19aec1c Compare August 28, 2020 19:29
@stuhood stuhood force-pushed the stuhood/rule-graph-converge branch from 19aec1c to 592db7b Compare August 28, 2020 19:41

// Should be called after a Node has been successfully reduced (regardless of whether it became
// monomorphic) to maybe mark it minimal.
let maybe_mark_minimal_in_set = |minimal_in_set: &mut HashSet<NodeIndex<u32>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this closure is actually closing over any variables here, so why not define it as a function scoped within the outer monomorphize function?

@@ -416,26 +447,43 @@ impl<'t, R: Rule> Builder<'t, R> {
} else {
continue;
};
if !matches!(node.node, Node::Rule(_)) {
continue;
match node.node {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: it would be nice to put the fall-through case at the bottom of the match. I also prefer to have an empty match statement return a () rather than an empty {} block, since the former is less verbose.

@@ -33,7 +33,7 @@ If a user makes a request to the engine that does not have a corresponding `Quer

`Params` are typed, comparable (`eq`/`hash`) values that represent both the inputs to `Rules`, and the building block of the runtime memoization key for a `Rule`. The set of `Params` (unique by type) that are consumed to create a `Rule`'s inputs (plus the `Rule`'s own identity) make up the memoization key for a runtime instance of the `Rule`.

It's important to note though that the `Params` in a `Rule` instance's identity will _not_ always become the positional arguments to that `Rule`: in many cases, a `Param` will be consumed by a `Rule`'s dependencies in order to produce an output value that becomes either a positional argument to the `Rule` as it starts, or the result of a `Get` while a coroutine `Rule` runs.
Copy link
Contributor

Choose a reason for hiding this comment

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

This paragraph had confused me. Good rewrite.

@@ -83,6 +83,7 @@ async def fibonacci(n: int) -> Fibonacci:
x, y = await Get(Fib, int(n - 2)), await Get(Fib, int(n - 1))
return Fibonacci(x.val + y.val)
```

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Add python to this, and Readme.io will make it look much prettier. Ditto on the above.


#### Monotonicity vs Global Information
One minimal problematic testcase (`fn wide_cycle` in `src/rust/engine/rule_graph/src/tests.rs`) looks like:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add an example of a non-problematic test case. For example, show what the graph looks like for the Fibonannaci example.

Also, consider adding pictures of the visualized graph. Readme.io allows you to upload pictures.

@stuhood
Copy link
Sponsor Member Author

stuhood commented Sep 1, 2020

Going to land this to continue building atop it. Thanks for the feedback: will apply in followups.

@stuhood stuhood merged commit 114ec84 into pantsbuild:master Sep 1, 2020
@stuhood stuhood deleted the stuhood/rule-graph-converge branch September 1, 2020 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve RuleGraph issue preventing codegen backend loading
4 participants