-
Notifications
You must be signed in to change notification settings - Fork 717
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
[macOS] net6-macos performance is 26x slower than the equivalent xamarin.mac #8890
Comments
I ran both samples, full screen (HD), with release builds
That makes XM/legacy between 1.28 times (Build) and 4.09 times (Change) faster than net6.0-macos. [1] Code is currently commented inside the repo I don't get anywhere as dramatic as 26x but I might be doing some things differently/incorrectly (or that number is about a subset of the benchmark sample). I'm also doing this on a M1-based Mac but running an Intel binaries, while slower, does not change the ratios significally. Unlike iOS there's no way to disable ObjC exceptions marshalling on CoreCLR 😢 I'll profile the sample to see if there are other places where the slowdown occurs... |
Access to That's more than 20 seconds out of the 2:30m benchmark run. Complete data attached to xamarin/xamarin-macios#15145 Fix xamarin/xamarin-macios#15146 Note: the same is also true of Dopes on Xamarin.Mac (legacy) comparison
note: Legacy was used since it's easier/faster to update and measure (and test two more cases) |
The same data shows another 6.25 seconds (out of the 2:30m benchmark run) is being spent inside Fix xamarin/xamarin-macios#15149 Just like the previous fix/PR this is not specific to macOS or CoreCLR and will benefit XI, XM and net6 performance. Still the performance ratio might vary a bit (since native calls are reduced and more costly on CoreCLR). Dopes on Xamarin.Mac (legacy) comparison
note: the above numbers do not include the perf enhancement of the previous fix |
Very nice findings!! This could explain some of the remaining differences we found when running net6.0-ios. |
The current dotnet project file (.csproj) does not link/trim on macOS release builds, while it's specified for XM legacy. diff --git a/src/dopes/Uno-dotnet6/DopeTestUno/DopeTestUno.Mobile/DopeTestUno.Mobile.csproj b/src/dopes/Uno-dotnet6/DopeTestUno/DopeTestUno.Mobile/DopeTestUno.Mobile.csproj
index a396d11..49ba4a7 100644
--- a/src/dopes/Uno-dotnet6/DopeTestUno/DopeTestUno.Mobile/DopeTestUno.Mobile.csproj
+++ b/src/dopes/Uno-dotnet6/DopeTestUno/DopeTestUno.Mobile/DopeTestUno.Mobile.csproj
@@ -66,6 +66,8 @@
</When>
<When Condition="'$(TargetFramework)'=='net6.0-macos'">
<PropertyGroup>
+ <RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
+ <TrimMode Condition="'$(Configuration)'=='Release'">link</TrimMode>
</PropertyGroup>
</When>
</Choose> Beside the usual trimming benefits the Xamarin linker does several binding optimizations (less for macOS since it allow JITing) like removing non-required code branches (that won't have to execute at runtime).
[1] Code is currently commented inside the repo Once things are merged I'll update the numbers and start looking at the native/unmanaged parts (even if I strongly suspect the lack of option to disable ObjC exceptions marshalling on CoreCLR to be the main culprit). |
One thought: you could enable exception marshalling on Legacy and see how much that slows it down. Then you could also enable the pinvoke wrapper code (xamarin/xamarin-macios#14961) and see how much speed you gain back. |
Updated numbers with the compounded effect of several fixes, in particular those three
Speedups with an updated Xamarin Mac SDK
Impact of ObjC exception marshallingNext this compares numbers when (the updated XM) has ObjC exception marshalling enabled (
In theory [1] we should see a similar between XM legacy and the dotnet numbers. The original numbers (in top in the issue) showed
which are close but hint at something more in case of the Build numbers [2]. Comparison with the updated numbers to be done shortly... [1] that the slowdown is caused only by the ObjC exception marshalling |
Comparing with ObjC exception marshalling enabledThis is XM (legacy) with ObjC exception marshalling (enabled) and net6.0-macos (where it's always enabled). A ratio of
[1] Code is currently commented inside the repo, comparison is not possible |
@rolfbjarne It's not yet possible to use the enable the pinvoke wrapper code to compare the performance. Filed as xamarin/xamarin-macios#15190 |
Comparing p/invoke wrappers enabledI had to hack around an issue (in quite an hackish way) but I was able to get the numbers
So the wrappers are helping a lot, net6.0-macos numbers are at best yet (see previous numbers) - but not quite what XM legacy was able to achieve. We can also compare the ratios (other numbers can't be compared due to other fixes that were applied) with the original numbers
The performance gap, between mono and coreclr runtimes, as narrowed considerably but still exists. [1] Code is currently commented inside the repo, comparison is not possible |
The Dope's Xamarin.Mac legacy project already has this setting. In order to compare apples-to-apples it's best to share the same settings between Xamarin.Mac legacy and net6.0-macos. Enabling the linker/trimmer does more than just removing unused code. It also optimize the bindings, removing code paths that are not used inside the app, e.g. removing 32bits code paths on 64bits builds. It's a good, performance enhancing, setting for release builds so it make sense to have it set inside samples - leading by example :) ref: unoplatform/uno#8890 (comment)
Comparing p/invoke wrappers enabled (updated)Updates
So net-6.0-macos number are between 7% and 12% slower using CoreCLR. Pre-Analysis Notes
Data Analysis
Conclusion
[1] Code is currently commented inside the repo, comparison is not possible |
Closing for improvements done in the runtime (xamarin/xamarin-macios#15145 (comment)) |
Current behavior
Run this xamarin.mac sample, then this sample for net6.0-macos.
You'll notice that the net6-macos performance is significantly lower than xamarin.mac performance.
Expected behavior
The performance is at least equal for both targets.
How to reproduce it (as minimally and precisely as possible)
No response
Workaround
No response
Works on UWP/WinUI
No response
Environment
No response
NuGet package version(s)
4.3.6
Affected platforms
macOS
IDE
No response
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
No response
The text was updated successfully, but these errors were encountered: