-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Release mode is way more slower than debug mode for user defined functions. #19677
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
Can you specify what kind of phone and which branch of Flutter did you use? |
Flutter Version:
Device: Motorola Moto G5 Plus, I don't think this is device specific issue because I also found a similar issue in Samsung Galaxy A5. I haven't tested it in other devices. One can simply verify it by running this file. |
I can confirm this on a Sony Xperia Z5 Compact: Debug build:
Release build:
|
I took a look: it's a combination of known issues. Here is the graph for
The first problem:
This can be worked around in user code by changing type annotation on After this change the graph becomes this:
Notice that
These are three separate problems.
/cc @aartbik this probably fits well into your overarching work on arithmetic so I am tentatively assigning this to you. |
On my desktop, with slightly larger request:
|
I added this to our internally monitored micro benchmarks. |
Note: spin off issues that are still pending: |
Rationale: Improves the slow path of 64-bit REM/TRUNCDIV on X64 and ARM64. Also introduces 64-bit negate operator, which was needed to expose negative contants (viz. x / -3 was represented as x / - (3) first). The negate operator is not recognized in AOT mode yet, since shifts by out-of-range constants should learn how to throw rather than deopt.... #33967 flutter/flutter#19677 Change-Id: I7d81c9b1c72d99e8c4018f68c0501c7b599e073f Reviewed-on: https://dart-review.googlesource.com/68280 Commit-Queue: Aart Bik <[email protected]> Reviewed-by: Alexander Markov <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
With some prototype code I have this down to the following. Still, we need to do better.
|
The 64-bit idiv on x86_64 is rather slow, so it makes sense to fast path this one even in the 64-bit case. With this and prototype code to deal with 1, 2, and 3 above I finally get the performance we want even on my desktop!
|
Rationale: Running an extra call specialization pass a bit later in the compiler passes stream (after types are propagated) recognizes more operators, which execute more efficiently. In addition, unboxing phis seems useful on all archs, not just 32-bit. These minor tweeks combined improve the prime number benchmark 3 fold. flutter/flutter#19677 Change-Id: Ib2102ce807c2f0a9f801542e0c4bc6a7673f552b Reviewed-on: https://dart-review.googlesource.com/69240 Reviewed-by: Vyacheslav Egorov <[email protected]> Commit-Queue: Aart Bik <[email protected]>
Rationale: Since 64-bit division requires twice as many cycles and has much higher latency compared to the 32-bit division, even for a non-speculative 64-bit path, a 32-bit "fast path" makes sense. Speedup: About 2x for cases that fit 32-bits. No noticable slowdown for the 64-bit cases. flutter/flutter#19677 #33967 Change-Id: I0d3b44564fee2cda03fc36f089a4424084732de0 Reviewed-on: https://dart-review.googlesource.com/69200 Commit-Queue: Aart Bik <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
Current status. With "bool isPrime(int n)" the performance of AOT is now on par with JIT.
With "bool isPrime(var n)", on the other hand, not all of the recent improvements take effect.
Although it is not unreasonable to request using "int" for performance critical parts, it would also be nice to delight our customers even more. So over to Alex who had some ideas on how to propagate "int" into the "var" declaration under AOT (or hand back to me with some pointers if you don't have the time). You will see a big improvement (3x) for the latter AOT case once the "int" is discovered. |
This change improves type flow analysis to infer int types, in addition to concrete classes (int type is abstract and has 2 concrete subclasses, _Smi and _Mint). Also, this CL enables devirtualization of dynamic calls (previously, only calls with known interface target were devirtualized). DartMicroBench.PrimeNumber: x64: +221% armv8: +461% armv7h: +47.98% No measurable impact on Flutter gallery build time in release mode. Issue: flutter/flutter#19677 Change-Id: I34db195f52f2a434218ee11eee7f308d4661738b Reviewed-on: https://dart-review.googlesource.com/69520 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
After latest check-in, "bool isPrime(var n)" is now on par too.
|
All has landed. |
(to be clear: landed in Dart SDK, next flutter roll will bring this into the flutter environment). |
This reverts commit 4d5b5bb. Reason for revert: We are seeing an AOT compiler issue as a result of this change (please see flutter/flutter#23879) Original change's description: > [vm/compiler] Fine tune operator and phi handling. > > Rationale: > Running an extra call specialization pass a bit later > in the compiler passes stream (after types are propagated) > recognizes more operators, which execute more efficiently. > In addition, unboxing phis seems useful on all archs, not > just 32-bit. These minor tweeks combined improve the prime > number benchmark 3 fold. > > flutter/flutter#19677 > > Change-Id: Ib2102ce807c2f0a9f801542e0c4bc6a7673f552b > Reviewed-on: https://dart-review.googlesource.com/69240 > Reviewed-by: Vyacheslav Egorov <[email protected]> > Commit-Queue: Aart Bik <[email protected]> [email protected],[email protected],[email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I46e420f9355bfc3c4a3f2fb9274f648e8a596d9a Reviewed-on: https://dart-review.googlesource.com/c/83229 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Aart Bik <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
This reverts commit 4d5b5bb. Reason for revert: We are seeing an AOT compiler issue as a result of this change (please see flutter/flutter#23879) Original change's description: > [vm/compiler] Fine tune operator and phi handling. > > Rationale: > Running an extra call specialization pass a bit later > in the compiler passes stream (after types are propagated) > recognizes more operators, which execute more efficiently. > In addition, unboxing phis seems useful on all archs, not > just 32-bit. These minor tweeks combined improve the prime > number benchmark 3 fold. > > flutter/flutter#19677 > > Change-Id: Ib2102ce807c2f0a9f801542e0c4bc6a7673f552b > Reviewed-on: https://dart-review.googlesource.com/69240 > Reviewed-by: Vyacheslav Egorov <[email protected]> > Commit-Queue: Aart Bik <[email protected]> [email protected],[email protected],[email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I46e420f9355bfc3c4a3f2fb9274f648e8a596d9a Reviewed-on: https://dart-review.googlesource.com/c/83229 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Aart Bik <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
This reverts commit cde4793. Reason for revert: the real underlying bug has been fixed Original change's description: > Revert "[vm/compiler] Fine tune operator and phi handling." > > This reverts commit 4d5b5bb. > > Reason for revert: We are seeing an AOT compiler issue as a result of this change (please see flutter/flutter#23879) > > Original change's description: > > [vm/compiler] Fine tune operator and phi handling. > > > > Rationale: > > Running an extra call specialization pass a bit later > > in the compiler passes stream (after types are propagated) > > recognizes more operators, which execute more efficiently. > > In addition, unboxing phis seems useful on all archs, not > > just 32-bit. These minor tweeks combined improve the prime > > number benchmark 3 fold. > > > > flutter/flutter#19677 > > > > Change-Id: Ib2102ce807c2f0a9f801542e0c4bc6a7673f552b > > Reviewed-on: https://dart-review.googlesource.com/69240 > > Reviewed-by: Vyacheslav Egorov <[email protected]> > > Commit-Queue: Aart Bik <[email protected]> > > [email protected],[email protected],[email protected],[email protected] > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Change-Id: I46e420f9355bfc3c4a3f2fb9274f648e8a596d9a > Reviewed-on: https://dart-review.googlesource.com/c/83229 > Reviewed-by: Siva Annamalai <[email protected]> > Reviewed-by: Aart Bik <[email protected]> > Commit-Queue: Siva Annamalai <[email protected]> [email protected],[email protected],[email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I7f9d892a6225c42810e7be52b6845bfee9cc017d Reviewed-on: https://dart-review.googlesource.com/c/83800 Reviewed-by: Aart Bik <[email protected]> Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Aart Bik <[email protected]>
This reverts commit cde4793. Reason for revert: the real underlying bug has been fixed Original change's description: > Revert "[vm/compiler] Fine tune operator and phi handling." > > This reverts commit 4d5b5bb. > > Reason for revert: We are seeing an AOT compiler issue as a result of this change (please see flutter/flutter#23879) > > Original change's description: > > [vm/compiler] Fine tune operator and phi handling. > > > > Rationale: > > Running an extra call specialization pass a bit later > > in the compiler passes stream (after types are propagated) > > recognizes more operators, which execute more efficiently. > > In addition, unboxing phis seems useful on all archs, not > > just 32-bit. These minor tweeks combined improve the prime > > number benchmark 3 fold. > > > > flutter/flutter#19677 > > > > Change-Id: Ib2102ce807c2f0a9f801542e0c4bc6a7673f552b > > Reviewed-on: https://dart-review.googlesource.com/69240 > > Reviewed-by: Vyacheslav Egorov <[email protected]> > > Commit-Queue: Aart Bik <[email protected]> > > [email protected],[email protected],[email protected],[email protected] > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Change-Id: I46e420f9355bfc3c4a3f2fb9274f648e8a596d9a > Reviewed-on: https://dart-review.googlesource.com/c/83229 > Reviewed-by: Siva Annamalai <[email protected]> > Reviewed-by: Aart Bik <[email protected]> > Commit-Queue: Siva Annamalai <[email protected]> [email protected],[email protected],[email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I7f9d892a6225c42810e7be52b6845bfee9cc017d Reviewed-on: https://dart-review.googlesource.com/c/83800 Reviewed-by: Aart Bik <[email protected]> Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Aart Bik <[email protected]>
I have noticed this problem as well and posted about it but nobody seems to know why this happens or even really care, the question seems to always get dismissed as BS. People keep asking for code because for some odd reason they don't understand the problem. CODE DOES NOT MATTER. Compile an app in release mode and it is slower! I found this out in a similar way by running some speed tests. |
It is unlikely that you noticed this problem, because this problem is actually fixed. It is highly possible however that you have encountered some other situation where AOT compiler does not do good optimisation job. Unfortunately it is impossible to say what exactly is going wrong without seeing the code, because reasons for the slow down are likely highly specific to the code. You might be using RegExp - which are slower in AOT builds, or you might be doing 64-integer math which is slow on ARM32, or you might be hitting a corner case in global type propagation which fails to infer some type which is critical for achieving good performance... The list is endless. We would be happy to look at the problem and figure if either us or you can do something to resolve it - but for that, unfortunately, you would need to provide more information about what exactly you are trying to do that gets slower. |
I am getting the same symptoms, where the code is slower in production than in development, when using in the same code in Android Phone. I was using this commands: flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi flutter build apk --release flutter run the environment: $ flutter doctor • No issues found! any tips or fixes? |
@eduardofcr you should profile your code and see where it is spending time (see https://flutter.dev/docs/perf/rendering/ui-performance and https://flutter.dev/docs/development/tools/devtools/cpu-profiler). Unfortunately without some more concrete details it is hard to give you any guidance. |
Problem solved. So, the 64 bit version was not generated. Now, the production version is faster than the development one! ;) No hangs, no waits! |
So what command should be used to ensure better release performance than debug? |
It depends on many factors. Are your release builds performing worse than debug? Did you try to profile your release builds? |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
I was trying to benchmark the performance of flutter and compare it with that of Java and C. So I chose a simple function to calculate nth prime number.
The problem is that the time taken to calculate the 20000th prime number in release mode (821 ms) was almost 8 times slower than that in debug mode (106 ms).
The method that I used is given below:
Full source code and benchmark result is available in this repository.
I know this is not a big issue and there are some serious issues which needs to be resolved. But I am creating this issue because I found that in debug mode, Flutter code was running faster than C (but only in debug mode).
If this issue is fixed for release mode, some CPU intensive tasks such as image processing could be easily (and quickly too!) performed in Dart without having the need to write them in C/C++.
The text was updated successfully, but these errors were encountered: