Remove redundant 'resolve_obligations_as_possible' call #13222
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! I was looking for a "good first issue" and saw this one: #7542. I like searching for performance improvements, so I wanted to try to find something useful there.
There are two tests in integrated_benchmarks.rs, I looked at 'integrated_highlighting_benchmark' (not the one discussed in the issue above).
Profile from that test looks like this:
22106 calls to
resolve_obligations_as_possible
seem like the main issue there.One thing I noticed (and fixed in this PR) is that
InferenceContext::resolve_ty_shallow
first callsresolve_obligations_as_possible
, and then callsInferenceTable::resolve_ty_shallow
. ButInferenceTable::resolve_ty_shallow
inside again callsresolve_obligations_as_possible
.resolve_obligations_as_possible
inside has a while loop, which works until it can't find any helpful information. So calling this function for the second time does nothing, so one of the calls could be safely removed.InferenceContext::resolve_ty_shallow
is actually quite a hot place, and after fixing it, the total number ofresolve_obligations_as_possible
in this test is reduced to 15516 (from 22106). "After change" time also improves from ~270ms to ~240ms, which is not a very huge win, but still something measurable.Same profile after PR:
The performance of this test could be further improved but at the cost of making code more complicated, so I wanted to check if such a change is desirable before sending another PR.
resolve_obligations_as_possible
is actually called a lot of times even when no new information was provided. As I understand,resolve_obligations_as_possible
could do something useful only if some variables/values were unified since the last check. We can store a boolean variable insideInferenceTable
, which indicates iftry_unify
was called after lastresolve_obligations_as_possible
. If it wasn't called, we can safely not callresolve_obligations_as_possible
again.I tested this change locally, and it reduces the number of
resolve_obligations_as_possible
to several thousand (it is not shown in the profile anymore, so don't know the exact number), and the total time is reduced to ~180ms. Here is a generated profile:Let me know if adding a new bool field seems like a reasonable tradeoff, so I can send a PR.