Skip to content
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

Mono interpreter #1438

Closed
davidbritch opened this issue Apr 18, 2023 · 2 comments · Fixed by #1507
Closed

Mono interpreter #1438

davidbritch opened this issue Apr 18, 2023 · 2 comments · Fixed by #1507
Assignees
Labels
doc-idea Indicates issues that are suggestions for new topics [org] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@davidbritch
Copy link
Contributor

davidbritch commented Apr 18, 2023

Many of the iOS-specific issues encountered in .NET MAUI are down to use of unsupported aspects of generics due to AOT compilation. In these circumstances, the Mono interpreter should be enabled (<UseInterpreter>true</UseInterpreter>). A benefit of this is reduction in overall IPA size.

The Mono interpreter is safe to enable for production apps. However, there are some drawbacks:

  • App size may be impacted for better or worse (it can go either way, it depends on the app code/usage).
  • Execution speed will be slower. However, this may range from ‘unmeasurable’ to ‘unacceptable’. You many not notice any performance hit at all for LOB apps but math-heavy apps/games could be a different story. You’d have to measure and assess if you’re ok with the performance hit.
  • Crash reports are less helpful since they’ll not show the real frames, but instead mention the interpreter executing things.

Use of the interpreter doesn’t have to be an all or nothing proposition. You can enable the interpreter on a more granular per-assembly basis using the MtouchInterpreter property. This enables you to:

  • Interpret all assemblies by specifying all or AOT compile everything by specifying -all
  • Interpret individual assemblies by specifying TheAssembly.dll or AOT compile individual assemblies by specifying -TheAssembly.dll
  • Mix and match to interpret some assemblies and AOT compile other assemblies

For example, in the app .csproj you can use an additive approach to AOT compile everything except for a specific third-party component for iOS release builds:

<PropertyGroup Condition=" '$(Configuration)|$(RuntimeIdentifier)'=='Release|maccatalyst-arm64' " >
    <MtouchInterpreter>-all,ThirdPartyComponent.dll</MtouchInterpreter>
</PropertyGroup>

The value is a comma-separated list of assemblies to interpret (if prefixed with a minus sign, the assemblies will be AOT-compiled instead), and ‘all’ can be used to specify all assemblies.

This means that you can either start with interpreting everything and then selecting which assemblies to AOT compile, or the opposite: AOT everything, and then select which assemblies to interpret:

<PropertyGroup>
    <!-- Interpret everything, except System.Xml.dll -->
    <MtouchInterpreter>all,-System.Xml.dll</MtouchInterpreter>
    <!-- AOT everything, except System.Numerics.dll, which will be interpreted -->
    <MtouchInterpreter>-all,System.Numerics.dll</MtouchInterpreter>
</PropertyGroup>

See also: dotnet/maui#13019


Associated WorkItem - 92650

@davidbritch davidbritch self-assigned this Apr 18, 2023
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Apr 18, 2023
@davidbritch davidbritch added doc-idea Indicates issues that are suggestions for new topics [org] Pri1 High priority, do before Pri2 and Pri3 and removed ⌚ Not Triaged Not triaged Pri3 labels Apr 18, 2023
@davidbritch
Copy link
Contributor Author

Another scenario is Mac Catalyst apps running on ARM64, which can throw an exception on launch (even when they work on x86). The launch exception can often be fixed by enabling the interpreter:

<PropertyGroup>
    <UseInterpreter>true</UseInterpreter>
</PropertyGroup>

This is necessary because we can't JIT code on ARM64 because macOS doesn't allow it. Therefore a combination of AOT compiler + interpreter is required.

@davidbritch davidbritch added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label May 25, 2023
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-idea Indicates issues that are suggestions for new topics [org] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants