6

We are in the process of migrating a Xamarin.iOS app to .NET iOS, in the early stages we found we were getting crashes with the Release config that were solved by adding <UseInterpreter>true</UseInterpreter>.

Our understanding was that this had the affect of disabling AOT compilation, and the errors we were getting would have been related to assemblies that weren't compatible with AOT.

Now our migration has matured we're keen not to lose out on the potential performance improvements AOT could bring. However if we re-enable AOT is there a technique we can use to identify the assemblies that aren't compatible?

1 Answer 1

5

Our understanding was that this had the affect of disabling AOT compilation

No, that is not what it does. It simply allows app to use an interpreter, for some bits of code that don't successfully AOT compile. Without this, MSBuild attempts to AOT compile everything. Your code, system code, third party libraries.

Short explanation:

With setting <UseInterpreter>True</UseInterpreter>, AOT compilation is still done wherever possible. App developer does not need to determine which modules should be excluded.

Details:

The Mono interpreter overcomes these restrictions while abiding by platform restrictions. It enables you to interpret some parts of your app at runtime, while AOT compiling the rest.

When you set UseInterpreter to True, it still AOTs everything it can in all assemblies, while bits of code that cannot be compiled to native code, are compiled to MSIL, then JIT-compiled at runtime.

Another way to enable the interpreter is to use MTouchInterpreter MSBuild property:

-all in the following example says to AOT compile all assemblies (that can be AOT compiled), while still allowing the interpreter to perform dynamic code generation:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <MtouchInterpreter>-all</MtouchInterpreter>
</PropertyGroup>

To be concluded, either using <UseInterpreter>True</UseInterpreter> or <MtouchInterpreter>-all</MtouchInterpreter> is fine as it AOTs everything it can in all assemblies, while some bits of code (such as generics, reflection) will be interpreted.

For more info, please refer to Enable the interpreter.

Sign up to request clarification or add additional context in comments.

3 Comments

Yeah thats fine, but is there a way to determine which assemblies shouldn't be part of AOT?
<UseInterpreter>true</UseInterpreter> is okay from the doc. You could see my updates.
@MobileDev: I also misunderstood what <UseInterpreter>True... does. Succinctly: AOT compilation is still done wherever possible. Therefore, there is no need for app developer to determine which modules should not be AOT'd. [IMHO, Maui should default to this setting on iOS.] I've edited the explanation in question, to make this clearer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.