Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context: #23991 Context: https://github.com/chabiss/periodictable In the above sample, a lot of time is spent in: 921.46ms (4.3%) mono!Android.Graphics.Paint.Cap.get_Butt() 872.40ms (4.1%) mono!Android.Graphics.Paint.Join.get_Miter() This exposes a performance issue with `Java.Lang.Enum` values: * `java.lang.Enum` in Java are objects (not `int` like C#) * When accessing an enum value, Java returns an object we have to wrap in a C# object. * .NET for Android has to do bookkeeping around this, lookup in a hash table, etc. To avoid this, we can store the `Join` and `Cap` values in a static field and avoid calling into Java. This approach is already working in .NET MAUI for `ImageView.ScaleType`: https://github.com/dotnet/maui/blob/9361f90a5d9eaf922432b36906ff18f6ccb2f52f/src/Core/src/Platform/Android/AspectExtensions.cs#L7-L10 After this change, the time spent is completely gone: 2.41ms (0.02%) mono.android!Android.Graphics.Paint.Join.get_Miter() I can't find the same call for (the unfortunately named) `get_Butt()` at all. In the future, we might consider changing the C# binding for `Java.Lang.Enum` to "auto-cache" values in C# static fields. Not sure if there is enough time left for it to happen in .NET 9, though.
- Loading branch information