You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Java.Interop uses the `JniAddNativeMethodRegistrationAttribute` custom
attribute to determine whether to register native methods for a given
type. It turns out that in most cases there isn't a single instance of
this attribute throughout the application and all the calls to
`GetCustomAttribute` end up returning nothing while incurring a large
performance penalty on application startup.
Eliminate the call after checking that no type in the application is
decorated with the above custom attribute.
Another observation made while profiling a couple of XA applications was
that the installation of the uncaught exception handler with
`Java.Lang.Thread` was quite expensive while, in most cases, completely
not useful during startup (and, hopefully, during application lifetime).
Instead of registering a managed type to handle the exceptions, register
the handler in Java which then calls down to Xamarin.Android native
runtime which, in turn, propagates the exception to the managed code.
Gains in startup time are quite nice:
Device name: **Pixel 3 XL**
Device architecture: **arm64-v8a**
Number of test runs: **10**
Test application: **Xamarin.Forms integration test**
| | **Native to managed** | **Runtime init** | **Displayed** | **Notes** |
|-----------------|------------------------|------------------|---------------|--------------------------------|
| **master** | 131.278 | 149.074 | 789.10 | preload enabled; 32-bit build |
| **this commit** | 49.446 | 66.989 | 764.30 | |
| **master** | 132.315 | 147.187 | 795.60 | preload disabled; 32-bit build |
| **this commit** | 48.876 | 63.822 | 754.30 | |
| **master** | 121.544 | 137.736 | 728.20 | preload enabled; 64-bit build |
| **this commit** | 45.350 | 61.464 | 699.50 | |
| **master** | 123.448 | 137.052 | 727.40 | preload disabled; 64-bit build |
| **this commit** | 44.765 | 58.047 | 689.00 | |
Device name: **Pixel 3 XL**
Device architecture: **arm64-v8a**
Number of test runs: **10**
Test application: Xamarin.Forms "Hello World" app with one label
| | **Native to managed** | **Runtime init** | **Displayed** | **Notes** |
|-----------------|------------------------|------------------|---------------|--------------------------------|
| **master** | 122.090 | 142.004 | 639.00 | preload enabled; 32-bit build |
| **this commit** | 44.370 | 63.803 | 586.10 | |
| **master** | 121.110 | 134.378 | 634.20 | preload disabled; 32-bit build |
| **this commit** | 45.085 | 57.992 | 580.40 | |
| **master** | 120.973 | 141.235 | 637.20 | preload enabled; 64-bit build |
| **this commit** | 44.767 | 63.846 | 578.50 | |
| **master** | 120.785 | 134.588 | 627.00 | preload disabled; 64-bit build |
| **this commit** | 44.859 | 57.590 | 575.40 | |
0 commit comments