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

TypeManager.CreateProxy does not cache constructor reflection #7479

Open
jeromelaban opened this issue Oct 20, 2022 · 1 comment
Open

TypeManager.CreateProxy does not cache constructor reflection #7479

jeromelaban opened this issue Oct 20, 2022 · 1 comment
Assignees
Labels
Area: App Runtime Issues in `libmonodroid.so`. Area: Performance Issues with performance. enhancement Proposed change to current functionality.
Milestone

Comments

@jeromelaban
Copy link

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

.NET 6 and 7

Description

The following piece of code is very expensive when manipulating native objects:

https://github.com/xamarin/xamarin-android/blob/91669a4e489104668fdd07382e40cf070aa559ac/src/Mono.Android/Java.Interop/TypeManager.cs#L327-L348

As there is no caching for getting constructors, in the worst case, twice:

image

Steps to Reproduce

Get ShapeDrawable.Paint in a loop.

Did you find any workaround?

None.

Relevant log output

No response

@jeromelaban jeromelaban added Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Oct 20, 2022
@jpobst jpobst added Area: Performance Issues with performance. and removed needs-triage Issues that need to be assigned. labels Oct 30, 2024
@jonathanpeppers
Copy link
Member

I can still see this in a recent .NET MAUI app:

Image

It looks like any API that returns a new instance of a Java.Lang.Object subclass would look up the constructor again.

  1. First call, Java object A: looks up constructor
  2. Second call, Java object A: already has a C# object, reuses object, doesn't call constructor at all
  3. Third call, Java object B: looks up constructor again

I think this could happen for commonly called APIs like View.Background that return unique Drawable instances. MAUI calls these a lot.

@jonathanpeppers jonathanpeppers added this to the .NET 10 milestone Oct 30, 2024
@jpobst jpobst added the enhancement Proposed change to current functionality. label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App Runtime Issues in `libmonodroid.so`. Area: Performance Issues with performance. enhancement Proposed change to current functionality.
Projects
None yet
Development

No branches or pull requests

5 participants