When recently profiling Xamarin.Android application startup, we observed that the profiler thought that strings were being allocated in locations that didn't make any sense. Is this a Profiler bug? A Mono issue? Cthulhu infecting our brains?
Two examples:
const variables are counted twice
Consider this generated code for Activity.OnCreate():
[Register ("onCreate", "(Landroid/os/Bundle;)V", "GetOnCreate_Landroid_os_Bundle_Handler")]
protected virtual unsafe void OnCreate (Android.OS.Bundle savedInstanceState)
{
const string __id = "onCreate.(Landroid/os/Bundle;)V";
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue ((savedInstanceState == null) ? IntPtr.Zero : ((global::Java.Lang.Object) savedInstanceState).Handle);
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
} finally {
}
}
The profiler claims that two strings are allocated when this method is invoked.
Strings from nothing
Consider this generated code for Activity.n_OnCreate_Landroid_os_Bundle_():
static void n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
{
Android.App.Activity __this = global::Java.Lang.Object.GetObject<Android.App.Activity> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
Android.OS.Bundle savedInstanceState = global::Java.Lang.Object.GetObject<Android.OS.Bundle> (native_savedInstanceState, JniHandleOwnership.DoNotTransfer);
__this.OnCreate (savedInstanceState);
}
Notice that it doesn't allocate any strings itself, and in a "hot path" (invoked more than once with the same parameters) no strings should be allocated, as __this and savedInstanceState will already be registered. (OK, perhaps savedInstanceState is new every time, but go with me here.)
The profiler reported that a string was being allocated in this method, and our interpretation of the profiler was that it was this method itself, not something called by this method.
What is the profiler talking about?
VS bug #660392
When recently profiling Xamarin.Android application startup, we observed that the profiler thought that strings were being allocated in locations that didn't make any sense. Is this a Profiler bug? A Mono issue? Cthulhu infecting our brains?
Two examples:
const variables are counted twice
Consider this generated code for
Activity.OnCreate():The profiler claims that two strings are allocated when this method is invoked.
Strings from nothing
Consider this generated code for
Activity.n_OnCreate_Landroid_os_Bundle_():Notice that it doesn't allocate any strings itself, and in a "hot path" (invoked more than once with the same parameters) no strings should be allocated, as
__thisandsavedInstanceStatewill already be registered. (OK, perhapssavedInstanceStateis new every time, but go with me here.)The profiler reported that a string was being allocated in this method, and our interpretation of the profiler was that it was this method itself, not something called by this method.
What is the profiler talking about?