Reputation: 2131
I am just starting to use ReactiveUI for my Xamarin Android and iOS projects. I noticed that my Android fragment that uses ReactiveUI takes a long time to load initially. For example when calling ReactiveCommand.Create for the very first time in my app, it takes about 250 milliseconds. Similar thing when calling the OneWayBind, WhenAny, BindCommand for the first time. But if I re-instantiate the view and view model again these methods return almost immediately ( < 3 ms).
public ReactiveCommand<Unit, Unit> ButtonCommand { get; }
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
ButtonCommand = ReactiveCommand.Create(() => Console.WriteLine("test"));
long test = sw.ElapsedMilliseconds;
Console.WriteLine(test);
To get around this issue I make random calls to the ReactiveUI API off main thread during the launching of the splash screen. Am I missing an initialization step for ReactiveUI that I missed in the documentation? Does anyone else have this issue? This is on Android, I have not tried iOS yet.
Update Thanks for the response Glenn, you are right. Ill try to investigate if my project settings are correct. The view model is in .NET Standard 2.0 project which has ReactiveUI and Fody package references. My Android project and Android library has ReactiveUI and RxUI.AndroidSupport. Below are the logs when calling ReactiveCommand.Create. Not sure why it is even probing WinForm, WPF, XamForms...
06-30 17:39:39.178 I/mono-stdout(28083): XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - start
06-30 17:39:39.222 D/Mono (28083): Loading reference 1 of System.Core.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
06-30 17:39:39.222 D/Mono (28083): Assembly Ref addref System.Core[0x7c76e09880] -> System[0x7c76dbbf80]: 8
06-30 17:39:39.239 D/Mono (28083): Loading reference 0 of /storage/emulated/0/Android/data/com.philips.CareTouch.B00/files/.__override__/Splat.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
06-30 17:39:39.239 D/Mono (28083): Assembly Ref addref Splat[0x7cd15ab900] -> mscorlib[0x7cd15a1480]: 29
06-30 17:39:39.244 D/Mono (28083): Loading reference 4 of /storage/emulated/0/Android/data/com.philips.CareTouch.B00/files/.__override__/Splat.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
06-30 17:39:39.244 D/Mono (28083): Assembly Ref addref Splat[0x7cd15ab900] -> System.Core[0x7c76e09880]: 6
06-30 17:39:39.284 D/Mono (28083): Loading reference 3 of /storage/emulated/0/Android/data/com.philips.CareTouch.B00/files/.__override__/ReactiveUI.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
06-30 17:39:39.284 D/Mono (28083): Assembly Ref addref ReactiveUI[0x7cd15ab600] -> System.Core[0x7c76e09880]: 7
06-30 17:39:39.287 D/Mono (28083): Loading reference 2 of /storage/emulated/0/Android/data/com.philips.CareTouch.B00/files/.__override__/Splat.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
06-30 17:39:39.287 D/Mono (28083): Assembly Ref addref Splat[0x7cd15ab900] -> System[0x7c76dbbf80]: 9
06-30 17:39:39.294 D/Mono (28083): Loading reference 7 of /storage/emulated/0/Android/data/com.philips.CareTouch.B00/files/.__override__/ReactiveUI.dll asmctx DEFAULT, looking for Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
06-30 17:39:39.294 D/Mono (28083): Assembly Ref addref ReactiveUI[0x7cd15ab600] -> Mono.Android[0x7c76dbbd00]: 17
06-30 17:39:39.347 D/Mono (28083): DllImport searching in: '__Internal' ('(null)').
06-30 17:39:39.347 D/Mono (28083): Searching for 'java_interop_jnienv_call_long_method_a'.
06-30 17:39:39.347 D/Mono (28083): Probing 'java_interop_jnienv_call_long_method_a'.
06-30 17:39:39.347 D/Mono (28083): Found as 'java_interop_jnienv_call_long_method_a'.
06-30 17:39:39.360 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.XamForms.dll'.
06-30 17:39:39.360 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.XamForms.exe'.
06-30 17:39:39.366 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.Winforms.dll'.
06-30 17:39:39.366 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.Winforms.exe'.
06-30 17:39:39.367 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.Wpf.dll'.
06-30 17:39:39.367 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.Wpf.exe'.
06-30 17:39:39.368 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.Uno.dll'.
06-30 17:39:39.368 D/Mono (28083): Assembly Loader probing location: '/Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/ReactiveUI.Uno.exe'.
06-30 17:39:39.489 I/mono-stdout(28083): XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - end
06-30 17:39:39.490 I/mono-stdout(28083): Elapsed 323
Upvotes: 1
Views: 761
Reputation: 2888
At the moment the way RxUI does it's dependent DLL loading is it uses the following class.
What happens is it has a list of hard coded strings, that match DLLs of NuGet packages we have. It will then attempt to load the DLLs listed in the list, and then if found, run IWantsToRegisterStuff
interface contained within the class.
I believe your slowness is happening because of this DLL registration.
The plan is very shortly to replace as part of the work in this task the plan is to make it so you call a Init method in the namespace of your DLL package against the RxApp instance. This work will come in ReactiveUI 11.
Upvotes: 2