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

Increased Runtime Duration for Java Functions in .NET Android Compared to Xamarin Android #9601

Open
MrAlbin opened this issue Dec 8, 2024 · 6 comments
Assignees
Labels
Area: Performance Issues with performance. need-attention A xamarin-android contributor needs to review

Comments

@MrAlbin
Copy link

MrAlbin commented Dec 8, 2024

Android framework version

net9.0-android, net8.0-android

Affected platform version

VS 2022 17.12.3

Description

I recently converted a Xamarin Android app to .NET Android (net8.0-android). I noticed that while the startup performance has improved, other functions are taking longer to execute at runtime. This is particularly evident when executing Java functions. In a simple comparison between Xamarin and .NET, I measured the following times for executing Java.Lang.Math.Sqrt:

  • Xamarin: 14 µs
  • .NET: 25 µs

How can this significant performance difference be explained?

Attached is a speedscope file that I recorded for the .NET app.
dotnet-dsrouter.exe_20241208_140545.speedscope.json

Steps to Reproduce

N/A

Did you find any workaround?

N/A

Relevant log output

@MrAlbin MrAlbin added the needs-triage Issues that need to be assigned. label Dec 8, 2024
@jpobst
Copy link
Contributor

jpobst commented Dec 9, 2024

Are you testing Debug or Release configurations? One change I'm aware of is that Debug uses an interpreter instead of a JIT for a better debugging experience.

You can disable this with <AndroidUseInterpreter>false</AndroidUseInterpreter>.

@jonathanpeppers Any other thoughts?

@jpobst jpobst added Area: Performance Issues with performance. and removed needs-triage Issues that need to be assigned. labels Dec 9, 2024
@jonathanpeppers
Copy link
Member

@MrAlbin you don't mention what configuration you were using to test this. AOT, LLVM, Interpreter, etc.? Debug mode has an interpreter by default in .NET 6+, while Xamarin had no interpreter at all.

Can you share the BenchmarkDotNet project(s)? I know there are currently a few workarounds to even run BenchmarkDotNet on Android.

@jpobst jpobst added the need-info Issues that need more information from the author. label Dec 9, 2024
@MrAlbin
Copy link
Author

MrAlbin commented Dec 9, 2024

I use Release configuration.

The sample app can be found here: https://github.com/MrAlbin/Benchmark

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Dec 9, 2024
@jonathanpeppers
Copy link
Member

I noticed you run BenchmarkDotNet in a custom way:

How do things compare if you run the standard BenchmarkDotNet pipeline like this:

BenchmarkDotNet does some statistics that is over my head, so I trust they do a better job at the math than I would by manually using Stopwatch.

@jonathanpeppers
Copy link
Member

Oh wait, you aren't using BDN at all. I just saw classes named Benchmark and thought you were.

@MrAlbin
Copy link
Author

MrAlbin commented Dec 10, 2024

I had initially tried BenchmarkDotNet but had issues getting it running with Xamarin Android. Thus I have done it without any benchmark library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Performance Issues with performance. need-attention A xamarin-android contributor needs to review
Projects
None yet
Development

No branches or pull requests

3 participants