-
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
Performance regression in pattern matching #36283
Comments
The timing suggests this might be an LLVM issue. We're getting more and more of these lately, which is concerning. |
Needs a P-tag. |
@nagisa also theorized that this was an LLVM problem (aliasing?). Do we have an easy way to test for that? |
Hmm. So I popped these examples into play and built the resulting assembly (on nightly, with optimizations enabled). They came out pretty similar:
|
Same results for beta: --- /home/nmatsakis/tmp/print-ok-beta 2016-09-15 12:22:36.604531321 -0400
+++ /home/nmatsakis/tmp/print-ref-beta 2016-09-15 12:23:04.984530867 -0400
@@ -10,6 +10,7 @@
.cfi_def_cfa_offset 80
cmpb $1, %dil
jne .LBB0_1
+ andb $3, %sil
cmpb $1, %sil
je .LBB0_7
cmpb $2, %sil |
Is it possible we fixed this? I know we did some LLVM fixing. cc @eddyb, I think you managed most of that. |
That said, stable builds are identical. Though I find it hard to imagine that the |
It could easily be something else, identical binaries are no guarantee, so the reduction could be unrelated. EDIT: as for LLVM, nothing I've seen would suggest any sort of improvements with |
Also, stable vs nightly look quite different, even if changing between the two versions of the arms makes |
@pmarcelll how confident are you that this reduction is accurate? can you make a version of the original benchmark available? |
Here's the code: link. |
The problematic part is in the hottest code path, so the slowdown is really noticable. |
Also, if the enum is not |
Discussed at compiler team meeting, but we didn't have a good answer for priority since investigation seems to be ongoing. P-high for now, feel free to downgrade if we get new info. |
Results of some investigation: I can reproduce a regression for this benchmark at the same point in the history, though its not as severe a regression. Gist with the (slightly modified, self-contained) bf interpreter benchmark, and the transcript + summary of my runs: https://gist.github.com/pnkfelix/9e727884890b1ec867d58bd280cbbf82 Interestingly, other small perturbations also remove the regression. In particular, even just pulling the body of that match arm into a separate method and marking that method |
If anyone has access to LLVM 3.8 that they can build Rust with, it would help to confirm that this is yet another LLVM 3.9 perf regression. |
@petevine Really useful, thanks! And so LLVM 3.9 delivers, yet another perf regression. |
As a followup note regarding the gist I posted: I have done a little digging into the generated assembly for the
In particular: the slower version on the left has an extra Anyway, at this point I'm inclined to agree with @eddyb that this is probably an LLVM issue, not a Rust compiler one. We could investigate the order and number of passes, or we could try to file an LLVM bug, but either way, I think we should downgrade the priority of this ticket. |
Inclined to agree. triage: P-medium |
I think the path forward is to file an LLVM bug. Next steps:
@eddyb notes that majnemer is often willing to do bisect against LLVM code base on small self-contained test case. |
Any update on this? :) |
It wasn't fixed in LLVM 4.0, but it might be fixed in 5.0, I'll check when the support is merged. The ergonomics improvements in pattern matching might also improve on this. |
Is it fixed now? :) |
I tried it a couple of days ago with the BF interpreter I linked earlier and it was slow no matter what compiler flag I used. As I wrote in the first comment, the benchmark completed just under 22 seconds, now it ran for 30 seconds with only a |
Any update on this? |
I tried it when All in all, |
I just checked it on nightly and it seems to be fixed (even on the latest beta). I don't know what changed, but I looked at the assembly on Godbolt and the previously slow part is now equivalent to the old version. I even managed to get the lowest runtime so far, only 19.543 seconds, with If this regression is unlikely to return and it was indeed fixed in LLVM then it can be closed. |
The LLVM issue has been fixed by llvm-mirror/llvm@238b886, which has tests and comments to prevent this from regressing without corresponding backend fixes. As such, I think we can consider this resolved... |
@nikic I was thinking about the bug report in #36283 (comment), it looks like that one can also be closed. |
I discovered the cause of a fairly big performance regression (from ~22s to ~29s in a specific benchmark) in my small BF interpreter and I succesfully minified the code:
On stable, both version of this code compiles to the exact same binary (and also on 1.9.0 and 1.10.0, both old-trans and MIR on each version respectively). On beta and nightly, the commented out code becomes slower. My understanding is that this should compile to the same binary, so this is incorrect behavior.
The last correct version is
rustc 1.12.0-nightly (7333c4ac2 2016-07-31)
, right before the update to LLVM 3.9.EDIT: I noticed that the minified example does compile to the same binary (I somehow got confused) so I added the
#[inline(never)]
.The text was updated successfully, but these errors were encountered: