Created attachment 14908 [details]
I noticed that default Xamarin implementation creates and release new Java.Lang.String on every text change, can be replaced with direct method call:
public string Text
if (this.TextFormatted == null)
return (string) null;
Java.Lang.String @string = value != null ? new Java.Lang.String(value) : (Java.Lang.String) null;
this.TextFormatted = (ICharSequence) @string;
if (@string == null)
You can reduce the amount of memory allocation for strings by replacing it at a direct method call:
if (TextView.id_setText_Ljava_lang_CharSequence_ == IntPtr.Zero)
TextView.id_setText_Ljava_lang_CharSequence_ = JNIEnv.GetMethodID(TextView.class_ref, "setText", "(Ljava/lang/CharSequence;)V");
IntPtr jobject = JNIEnv.NewString(value); //Instead of create String wrapper using direct handle
JValue* parms = stackalloc JValue;
*parms = new JValue(jobject);
JNIEnv.CallVoidMethod(this.Handle, TextView.id_setText_Ljava_lang_CharSequence_, parms);
I think you can improve not only setter but also the getter but it will be a little harder because you need to call ToString method on ICharSequence handle.
I tested it on my device performance has grown by 5 times.
I added project with performance test.
Has anyone looked into this yet? I would love to see some more performance data on this considering the discrepancies between android the the other platforms in performance.