-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 time complexity of equality relations #32062
Improve time complexity of equality relations #32062
Conversation
This is an alternative solution to the same compilation time problem as in #32042. This on the other tackles the problem in a much more complex way which may add a slight slow down for typechecking in the normal case due to its increased complexity (most of the time This change essentially makes it so that when two variables are stated to be equal the relation is immediately created and made available to users of the Minimal example which displays this issue, add on more calls to the
Fixes #21231 |
This does not currently fix the compile times of the example @asajeffrey posted. I do however have a theory about that specific issue which I will investigate closer. If it turns out to be correct then this PR (or something close to it) is almost guaranteed to be necessary to solved the issue). In the iterator chaining example (pasted below) the main problem is the large number of instantiations of associated types. #20304 indicates that this should be possible to solve by adding making Example:
Ideally the second case would work as well but I am unaware of a key-value data structure where the keys may change.
|
That looks +1. I want to check how this affects performance on normal rustc builds. |
Pushed a minor change to avoid retrieving the root variable more than is necessary. Also renamed "parent_*" to "root_" as that seems more like the naming scheme in the unification table module. |
☔ The latest upstream changes (presumably #32056) made this pull request unmergeable. Please resolve the merge conflicts. |
d78fefb
to
5cfd971
Compare
@Marwes I didn't get a chance to read this patch in detail yet, but I was actually thinking of taking precisely this same approach for other independent reasons, so I'm definitely +1 on the overall idea. I'll try to take a look tomorrow! |
Can you add the test case that you mention here into the repo? How about making a directory Another option -- perhaps a better option -- is to add the test case to as a PR to https://github.com/nrc/rustc-perf. I plan to do this in any case though =) along with a few other similar microbenchmarks for extreme cases. |
I assume that it won't be run during |
@nikomatsakis I read all your comments and I will go through and do a commit tomorrow. |
Those two commits should fix all nits. I can rebase and squash all commits if that would be cleaner. I tried an alternate way of handling relations as well. I figured it may be more memory efficient to move the non-root relation vector into the |
Seems that make tidy fails because of the missing license. I tried copying the license from a different file but that does not solve it. Any ideas? |
@Marwes, |
d027683
to
ea4a051
Compare
@steveklabnik I only added it locally and tested running make tidy after which it still failed. Anyway, turns out the file had CRLF line endings locally as I had copy pasted the example from this PR. Fixed that and amended the commit so it should pass now. |
I am not able to reproduce the current travis failure locally so I am unfortunately not sure how to fix it. |
I'm trying to reproduce locally. |
r=me btw -- I think we can (and will) do some more work in this area, but this seems like a great step forward. But let's see if we can get to the bottom of this travis failure. |
Were a bit busy last week but I finally got time to go through the changes again. Turns out I missed/forgot that drop is not called until after the function is called when in argument position. Still not sure why I can't reproduce it locally (might be because of different order of iteration over a hashmap somewhere I guess?). Let me know if I should rebase. |
On Sun, Mar 20, 2016 at 06:38:07AM -0700, Markus Westerlind wrote:
OK, please do rebase. I am also surprised that I didn't see this |
This PR adds a `UnificationTable` to the `TypeVariableTable` type which is used store information about variable equality instead of just storing them in a vector for later processing. By using a `UnificationTable` equality relations can be resolved in O(n) (for all realistic values of n) rather than O(n!) which can give massive speedups in certain cases (see combine as an example). Link to combine: https://github.com/Marwes/combine
c6a771f
to
e00cdd7
Compare
Rebased |
@bors r+ |
📌 Commit e00cdd7 has been approved by |
@Marwes it would be fantastic if you could upload that test case to https://github.com/nrc/benchmarks -- you just have to make a |
Add a test on @nikomatsakis for the improvement for equality relations implemented in rust-lang/rust#32062
Add a test on @nikomatsakis suggestion for the improvement for equality relations implemented in rust-lang/rust#32062
…ikomatsakis Improve time complexity of equality relations This PR adds a `UnificationTable` to the `TypeVariableTable` type which is used store information about variable equality instead of just storing them in a vector for later processing. By using a `UnificationTable` equality relations can be resolved in O(n) (for all realistic values of n) rather than O(n!) which can give massive speedups in certain cases (see combine as an example). Link to combine: https://github.com/Marwes/combine
This PR adds a
UnificationTable
to theTypeVariableTable
type which is used store information about variable equality instead of just storing them in a vector for later processing. By using aUnificationTable
equality relations can be resolved in O(n) (for all realistic values of n) rather than O(n!) which can give massive speedups in certain cases (see combine as an example).Link to combine: https://github.com/Marwes/combine