-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Performance issues with match type reduction #12267
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
Comments
WIP update: Flamegraph for compiling stdlib
Compile times after warmup (on my local machine)
|
So it's clearly not Tuple.scala where the tryMatchAlias calls are made. Question to ask: for which files are they made? And why do they take so much time? I instrumented everything else. It's really just those ~600 calls to tryMatchAlias that make all the difference. Nothing else is invoked at all. |
From the data we have, it seems that the slowdown comes from the exhaustivity check (mostly redundency check). If we disable exhaustivity check, then the numbers go back as before. The current flamegraph does not show enough stack depth to see where it reaches |
What I am seeing is
This seems to be a very specific case. The only classes inheriting from Tuple are Tuple1 to Tuple 22 and a slowdown for them is not indicative of a slowdown elsewhere. On the other hand, we should verify whether there is some bottleneck in match type reduction. Such a big slowdown for ~600 calls looks excessive. |
I verified that all calls to tryMatchAlias originate from RefChecks, with the stacktrace like this:
So I don't think exhaustivity was to blame for the original slowdown (but I noticed a further slowdown on top of the first one, which might well be due to it). |
I agree. The exhaustivity check becomes much more expensive after #12153. In the flamegraph, you can search |
#12300 gives some more data. @liufengyun can you try to dig deeper on this? |
Thanks for the tips, I'll conduct a deeper analysis of the problem. |
[WIP Update] Before #12153, the --- a/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala
+++ b/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala
@@ -8,6 +8,7 @@ trait ConstraintRunInfo { self: Run =>
private var maxSize = 0
private var maxConstraint: Constraint = _
def recordConstraintSize(c: Constraint, size: Int): Unit =
+ if size > 100 then println("Constraint.size = " + size)
if (size > maxSize) {
maxSize = size
maxConstraint = c And we have 4638553 recorded constraints
|
The root cause of the performance regression is that
|
To enforce the invariant, we need to ensure that tvars are instantiated at end of phases.
Fixed in #12333. |
Uh oh!
There was an error while loading. Please reload this page.
#12153 introduce a performance regression for the stdlib test. I tracked it down to attempts to do match type reductions that seem very slow.
I saw that overall there were 566 attempts at match type reductions, presumably when compiling the Tuple.scala (and maybe also Tuples.scala) files. Without the change to translucentSuperType there were none. But the change is necessary and 566 does not seem an excessive number. Nevertheless these reduction attempts (which all fail in the end) seem responsible for the significant slowdown of stdlib compilation as a whole.
We should get to the bottom of this. As a first step, we should try to get a flamegraph or other profile just for compiling Tuple.scala and Tuples.scala. Once we know where the slowdown happens we should see what we can do to optimize.
The text was updated successfully, but these errors were encountered: