-
Notifications
You must be signed in to change notification settings - Fork 63
[Java.Interop] remove Type.GetTypeInfo() calls #557
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
Conversation
e3249a1 to
e6f02f9
Compare
| { | ||
| var t = typeof (Environment).GetTypeInfo (); | ||
| var m = t.DeclaredMethods.FirstOrDefault (x => x.Name == "FailFast"); | ||
| var m = typeof (Environment).GetMethod ("FailFast"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was public so default BindingFlags should work: https://github.com/mono/mono/blob/3563bd90dc54f74a33ca468d0e2eb0d189a89dc1/mcs/class/corlib/System/Environment.cs#L921
It looks like Environment.FailFast is still not in netstandard 2.0, so we have to use reflection here.
Java.Interop used to be a PCL, but is now a netstandard 2.0 library. We make use of `IntrospectionExtensions.GetTypeInfo`: https://github.com/mono/mono/blob/c5b88ec4f323f2bdb7c7d0a595ece28dae66579c/mcs/class/referencesource/mscorlib/system/reflection/introspectionextensions.cs#L24 https://github.com/mono/mono/blob/c5b88ec4f323f2bdb7c7d0a595ece28dae66579c/mcs/class/corlib/ReferenceSources/RuntimeType.cs This is a "compat layer", because some of the System.Reflection APIs are different for PCLs and netstandard 1.x. If we remove these calls, and just use the regular `System.Type` APIs the code is simpler and makes less method calls. API differences to mention: * `TypeInfo.GetDeclaredNestedType` is equivalent to `Type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)` * `TypeInfo.DeclaredConstructors` is equivalent to `Type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)` Places checking `IsStatic` can drop `BindingFlags.Static`. ~~ Results ~~ Testing a Release build of the Xamarin.Forms integration project in xamarin-android: Before: 01-09 16:21:41.904 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +756ms 01-09 16:21:45.886 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +749ms 01-09 16:21:49.851 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +758ms 01-09 16:21:53.818 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +757ms 01-09 16:21:57.785 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +747ms 01-09 16:22:01.783 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +763ms 01-09 16:22:05.832 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +756ms 01-09 16:22:09.782 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +754ms 01-09 16:22:13.798 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +757ms 01-09 16:22:17.798 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +757ms Average(ms): 755.4 Std Err(ms): 1.43913554299486 Std Dev(ms): 4.55094617756694 After: 01-09 17:07:41.164 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +757ms 01-09 17:07:45.148 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +758ms 01-09 17:07:49.113 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +747ms 01-09 17:07:53.096 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +748ms 01-09 17:07:57.062 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +747ms 01-09 17:08:01.045 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +756ms 01-09 17:08:05.012 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +745ms 01-09 17:08:08.994 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +753ms 01-09 17:08:13.011 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +765ms 01-09 17:08:17.026 1473 1503 I ActivityTaskManager: Displayed Xamarin.Forms_Performance_Integration/xamarin.forms.performance.integration.MainActivity: +752ms Average(ms): 752.8 Std Err(ms): 1.98774020211674 Std Dev(ms): 6.28578643537236 This might save ~3ms on startup? Comparing the number of calls: Method call summary Total(ms) Self(ms) Calls Method name - 4 3 3457 System.Reflection.IntrospectionExtensions:GetTypeInfo (System.Type) + 3 2 3020 System.Reflection.IntrospectionExtensions:GetTypeInfo (System.Type) This reduced ~437 calls. Xamarin.Forms still supports netstandard 1.x, so that is where some of the remaining calls are coming from.
e6f02f9 to
7104cf4
Compare
Java.Interop used to be a PCL, but is now a netstandard 2.0 library.
We make use of
IntrospectionExtensions.GetTypeInfo:https://github.com/mono/mono/blob/c5b88ec4f323f2bdb7c7d0a595ece28dae66579c/mcs/class/referencesource/mscorlib/system/reflection/introspectionextensions.cs#L24
https://github.com/mono/mono/blob/c5b88ec4f323f2bdb7c7d0a595ece28dae66579c/mcs/class/corlib/ReferenceSources/RuntimeType.cs
This is a "compat layer", because some of the System.Reflection APIs
are different for PCLs and netstandard 1.x.
If we remove these calls, and just use the regular
System.TypeAPIsthe code is simpler and makes less method calls.
API differences to mention:
TypeInfo.GetDeclaredNestedTypeis equivalent toType.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)TypeInfo.DeclaredConstructorsis equivalent toType.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)Places checking
IsStaticcan dropBindingFlags.Static.Results
Testing a Release build of the Xamarin.Forms integration project in
xamarin-android:
This might save ~3ms on startup?
Comparing the number of calls:
This reduced ~437 calls. Xamarin.Forms still supports netstandard 1.x,
so that is where some of the remaining calls are coming from.