Xamarin.Forms Performance Reminder – Fast Renderers

This post is first of a series of “reminders” that will help your Xamarin.Forms apps become as performant as possible. This time we will use Fast Renderers to squeeze additional performance from our apps when running on Android.

Xamarin

What are Fast Renderers?

Xamarin.Forms controls are displayed in native view using Renderers. Absolute most of the Xamarin.Forms Android renderers derive from ViewRenderer<TView, TNativeView> class which is defined as follows:

Diving further, VisualElementRenderer<TElement> is defined as:

Here FormsViewGroup is actually just a customized Xamarin.Forms class derived from ViewGroup. The actual native Android view (like a Button) gets embedded in this outer ViewGroup. This is done to supply additional “global” behavior of most controls like padding, gesture handling, etc., but it also has clear performance impact – every control you create in fact generates two views in Android’s view hierarchy. This is fine for simpler app pages, but for complex and large lists, this might become a serious performance bottleneck. Luckily, Fast Renderers are here for the rescue.

When you enable Fast Renderers for your project, they will automatically replace the default renderers for the most common controls:

  • Button
  • Image
  • Label
  • Frame

Fast Renderers no longer derive from ViewRenderer<TView, TNativeView> and instead handle all layout and gesturing on the native control itself. For an example see the Fast Renderer for Button here on GitHub.

How to enable Fast Renderers?

Fast Renderers are an experimental feature and are not enabled by default. You can enable them for the whole project by putting the following line of code before Forms.Init() in your Android project head’s MainActivity:

Internally the flag for Fast Renderers is set and then initialized during LoadApplication in FormsAppCompatActivity as seen here in the source code.

It is important to note that Fast Renderers are only compatible with app compat activity and will have effect only on Android.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.