-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 issue with min and max methods in dart:math #34090
Comments
We are working on this. We need to introduce checked and unchecked entries into closures for this to become faster. |
The regression has mostly been addressed. There is still an %18 regression, but it is not grossly unusable as before. I will dig further into the cause of the regression when time permits. |
The remaining regression appears to be due to the fact that we aren't optimizing the arithmetic inside |
@sjindel-google I think it is actually this chunk of code - have special optimization for We should figure out if we can make that work when type arguments are passed as well. |
I added a microbenchmark to our internal tracking system. JIT
AOT
|
Difference for the innermost static call to max or > operator between list.reduce(math.max) and list.reduce((a, b) => a > b ? a : b) closures under AOT:
vs
|
For JIT, I prototyped mraleph's idea by inlining MathMinMax even when the type parameter is present. This yields the following intermediate.
This increased performance a bit, but not as much as I had hoped. Profiling the generated JIT code reveals that we spent more time in the AssertAssignable code than in the Max code itself. So next we should explore if this can be further simplified. |
@aartbik IIRC Currently unchecked entry points are disabled (due to some missing stuff in regalloc). You can try |
Yes, with my prototype and unchecked entry points, we see great jump in performance (unchecked entry points standalone helps too, but not as much as the combination). Profiling max_max reveals that in this context, other than data fetching and testing, the time is actually spent doing the max operator. |
Dart 2.1 has been released which fixes the problem with this test: dart-lang/sdk#34090
Well, from my point of view the issue seems to be fixed in Dart 2.1 and I am closing this issue. You are welcome to reopen the issue if you guys thinks there are still more there can be done on this matter. |
We probably can do a bit better, so I like to keep this open. I removed the medium tag though. |
With ToT, the prototype of recognizing min/max no longer moves the performance needle either way, so no point pursuing this further. We can indeed close the issue. |
Dart SDK Version (
dart --version
)Problematic version:
Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on "windows_x64"
Compared against:
Dart VM version: 1.24.3 (Wed Dec 13 18:05:29 2017) on "windows_x64"
Whether you are using Windows, MacOSX, or Linux (if applicable)
Windows 10 64 bit.
Whether you are using Chrome, Safari, Firefox, Edge (if applicable)
Running as standalone with dart.exe
When running the following code in Dart 2.0.0 and Dart 1.24.3:
I got the following timings:
With the observatory I can see the CPU usage in Dart 2.0 are used on something called DRT_SubtypeCheck:
If I modify the code to not use the math.max method:
Then I gets the following timings:
I should note that the same issue can also be reproduced for math.min.
The text was updated successfully, but these errors were encountered: