• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    C#
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Xamarin.Forms Performance Playground (Layouts, Bindings, XAMLC, etc)

Xamarin.Forms Performance Playground

There are many techniques for increasing the performance of Xamarin.Forms applications. Collectively these techniques can greatly reduce the amount of work being performed by a CPU, and the amount of memory consumed by an application. This repository describes and discusses these techniques.

(Work in progress)

  • Bindings
  • CollectionView
  • Fast Renderers
  • HttpClient
  • Images
  • IoC
  • Layouts
  • Shell
  • Startup
  • Visual
  • XAMLC

Bindings

Don't use bindings for content that can be set statically. For example, setting Button.Text = "Accept" has less overhead than binding Button.Text to a ViewModel string property with value "Accept".

Bindings

CollectionView

And before the CollectionView arrived...

ListView

ListViews are often used to display much more data than can fit onscreen.

Xamarin.Forms permits ListView cell re-use through the ListViewCachingStrategy enumeration, which has the following values:

  • RetainElement. It is the default value to guarantee compatibility with previous versions of Xamarin.Forms. The ListView creates a new cell for each element in the list.
  • RecycleElement.
  • RecycleElementAndDataTemplate.

Other recommendations:

  • In certain cases additional content is required to the ListView in the top and/or botton part. It is recommended to use the HeaderTemplate and FooterTemplate properties for this.
  • Wrapping the ListView control in a ScrollView breaks virtualization!.
  • It is recommended to use IList as ItemsSource instead of IEnumerable.
  • If RecycleElemement is used, performance is increased by removing Binding from the cell and using OnBindingContextChanged.

CollectionView

The CollectionView is a flexible and performant view for presenting lists of data using different layout specifications.

In addition to allowing different layouts, the CollectionView has better performance than the ListView, but... how much does it improve the performance?.

CollectionView

CollectionView Create Renderer

One of the biggest changes between ListView and CollectionView is the removal of wrapping content in a ViewCell. This allows for significant gains to performance, especially on Android, while remaining familiar to what you’ve done before when using the ListView.

While the impact on the startup time is not noticeable (is more reduced), can appreciate a noticeable difference in memory consumption.

Fast Renderers

Traditionally, most of the original control renderers on Android are composed of two views:

  • A native control, such as a Button or TextView.
  • A container ViewGroup that handles some of the layout work, gesture handling, and other tasks.

However, this approach has a performance implication in that two views are created for each logical control, which results in a more complex visual tree that requires more memory, and more processing to render on screen.

Fast renderers reduce the inflation and rendering costs of a Xamarin.Forms control into a single view.

Fast renderers are available for the following controls in Xamarin.Forms on Android:

  • Button
  • Image
  • Label
  • Frame

NOTE: Xamarin.Forms 4 use the Fast Renderers by Default.

The results:

Fast Renderers

NOTE: Using a Oneplus 6 device with AOT and XAMLC (Release mode).

HttpClient

Many mobile applications depend on external data making intensive use of the network. Therefore, we are interested in having the fastest possible response when making HTTP requests.

Take the approach of using a single HttpClient instance per server (reuse HttpClient between requests). This will get you better performance.

The results:

HttpClient

This is because will segregate things each server may depend on such as cookies or DefaultRequestHeaders.

A common mistake working with HttpClient is to download json to a string. The problem is that this creates a string of your entire JSON document needlessly.

This has two problems:

  • Depending on the size of the downloaded file to chain, it will affect more than the necessary time.
  • Higher memory consumption.

Other recommendations:

  • Use GZIP (or deflate) where possible.
  • Use Xamarin's Native HttpMessageHandlers.

Images

Displaying image resources can greatly increase the app's memory footprint. Next, we make a comparison of memory consumption between the use of images with Xamarin.Forms, with FFImageLoading and with GlideX.

Images

In Xamarin.Forms 4.0 there are improvements related to image management. You can find a sample and Excel with comparative data between 3.6 and 4.0. After several measurements and making averages, the image memory consumption has dropped by 15% on average.

IoC

Comparative performance in the registry and in the dependency resolution of the most used containers when developing with Xamarin.Forms:

IoC

(Work in progress)

Layouts

A Layout represents a node in the visual tree. A Layout has properties and events that allow to define its behavior.

It is responsible for managing the location and size of secondary nodes.

Examples: StackLayout, Grid, etc.

Layouts

The creation of a Xamarin.Forms layout goes through two phases:

  • Invalidation cycle: The process of recursive notification to the parent node.
  • Layout cycle: After invalidating, we proceed to the reorganization of elements marked as "invalidated".

The Invalidation cycle: Invalidation

The Layout cycle: Layout

In the following chart we have the time in milliseconds of UpdateChildrenLayout in each Layout. The example to render:

The result:

Layouts

Grid

The Grid organizes child elements into rows and columns. It allows to create complex structures without the need for large nests.

The size of each row and column is important, and affects performance. We must take care of the use of cells and rows.

To consider:

  • Using Auto in ColumnDefinition or RowDefinition, the invalidation of one of the children Views causes the chain invalidation of the visual tree of the grid.
  • Using fixed values in ColumnDefinition or RowDefinition, the Grid ignores any notification of invalidation of its children.
  • Using * in ColumnDefinition or RowDefinition, the Grid ignores any notification of invalidation of the children.

StackLayout

The StackLayout organizes views in a one-dimensional line ("stack"), either horizontally or vertically. Views in a StackLayout can be sized based on the space in the layout using layout options. Positioning is determined by the order views were added to the layout and the layout options of the views.

It can lead to excessive nesting.

The invalidation of a child View causes the chain invalidation in the visual tree until the StackLayout.

RelativeLayout

The RelativeLayout organizes the child elements based on relationships between the different elements and the container. Ideal when the size or positioning should be dynamic and adapt to different conditions.

It is the layout with lowest performance. High CPU consumption.

Other Recommendations:

  • Do not use StackLayout for just one child.
  • Do not use StackLayout when you can use Grid.
  • Do not nest several StackLayouts when you can use a Grid.
  • When using a Grid, try to ensure that as few rows and columns as possible are set to Auto size. Each auto-sized row or column will cause the layout engine to perform additional layout calculations.
  • When using an AbsoluteLayout, avoid using the AbsoluteLayout.AutoSize property whenever possible.
  • The RelativeLayout gives many possibilities but its performance is worse than the FlexLayout.

Shell

Xamarin.Forms Shell reduces the complexity of mobile application development by providing the fundamental features that most mobile applications require. This includes a common navigation user experience, a URI-based navigation scheme, and an integrated search handler.

In addition, Shell applications benefit from an increased rendering speed, and reduced memory consumption.

Shell

NOTE: Chart using an Android device in Release mode and AOT.

In the case of Android, the startup time does not improve (for now) the default renderers while the memory consumption is slightly better.

Startup

JIT, AOT and other concepts have an impact on the startup time of the App.

Ahead of Time Compilation builds everything upfront, to avoid JIT when first running your app. When this option is enabled, Just In Time (JIT) startup overhead is minimized by precompiling assemblies before runtime. The resulting native code is included in the APK along with the uncompiled assemblies. This results in shorter application startup time, but at the expense of slightly larger APK sizes.

Startup

Startup Sizes

NOTE: Using a Oneplus 6 device (Release mode).

Visual

Material Design is an opinionated design system created by Google, that prescribes the size, color, spacing, and other aspects of how views and layouts should look and behave.

Xamarin.Forms Material Visual can be used to apply Material Design rules to Xamarin.Forms applications, creating applications that look identical, or largely identical, on iOS and Android. When Material Visual is enabled, supported views adopt the same design cross-platform, creating a unified look and feel. This is achieved with material renderers, that apply the Material Design rules.

Material renderers are currently included in the Xamarin.Forms.Visual.Material NuGet package for the following views:

  • Button
  • Entry
  • Frame
  • ProgressBar
  • DatePicker
  • TimePicker
  • Picker
  • ActivityIndicator
  • Editor
  • Slider
  • Stepper

Functionally, the material renderers are no different to the default renderers. But ... what about the performance?.

Visual

Visual CreateRenderer

All current Visual renderers with Material use the Fast Renderers model. This makes most Material renderers faster than the default ones. In the case of the Entry, in Material have more layers, animations, etc. It is the only case that gets worse (for now).

The Visual performance tests have been made with:

  • Release Mode, AOT, XAMLC (for startup times).
  • Average of 5 times.
  • Physical device (Oneplus 6).

XAMLC

XAML can be optionally compiled directly into intermediate language (IL) with the XAML compiler (XAMLC).

XAML compilation offers a number of a benefits:

  • It performs compile-time checking of XAML, notifying the user of any errors.
  • It removes some of the load and instantiation time for XAML elements.
  • It helps to reduce the file size of the final assembly by no longer including .xaml files.
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]

The result:

XAMLC

Copyright and license

Code released under the MIT license.

More Repositories

1

xamarin-forms-goodlooking-UI

Xamarin.Forms goodlooking UI samples
2,540
star
2

awesome-dotnet-maui

A curated list of awesome .NET MAUI libraries and resources.
1,773
star
3

awesome-xamarin-forms

A curated list of awesome Xamarin.Forms libraries and resources
C#
1,246
star
4

dotnet-maui-showcase

A curated list of awesome .NET MAUI samples
849
star
5

Xamanimation

Xamarin Forms Animation Library
C#
460
star
6

TemplateUI

A set of Xamarin.Forms templated controls.
C#
422
star
7

AlohaKit.Controls

A set of .NET MAUI drawn controls.
C#
389
star
8

figma-to-maui-graphics

FigmaSharp.Maui.Graphics turns your Figma design into .NET MAUI Graphics code
C#
330
star
9

AlohaKit.Animations

AlohaKit.Animations is a library designed for .NET MAUI that aims to facilitate the use of animations to developers.
C#
214
star
10

netmaui-chat-app-challenge

Chat App UI Challenge made with .NET MAUI.
C#
214
star
11

xamarin-forms-page-transitions

Custom page transitions in a Xamarin.Forms App
C#
211
star
12

xamarin-forms-netflix-sample

A Xamarin.Forms version of the Netflix app to prove you can create goodlooking UI with Xamarin.Forms.
C#
194
star
13

forms-gtk-progress

Xamarin.Forms GTK Backend Progress
191
star
14

AlohaKit.Layouts

.NET MAUI Layouts Library
C#
120
star
15

Art-Plant-Mall

Xamarin.Forms goodlooking UI sample.
C#
111
star
16

MyTripCountdown

Xamarin.Forms goodlooking UI sample
C#
108
star
17

xamarin-forms-to-net-maui

This repository is a compilation with documentation, examples and tips when converting code from Xamarin.Forms to .NET MAUI.
C#
104
star
18

AlohaKit.UI

This library offers an easier way to create drawn controls in .NET MAUI in both XAML and C#.
C#
101
star
19

PulseMusic

Xamarin.Forms goodlooking UI sample
C#
88
star
20

ways-create-netmaui-controls

In this repository we collect all the ways to create or extend controls in .NET MAUI.
C#
86
star
21

xamarin-forms-gtk-movies-sample

The Movie DB Xamarin.Forms Sample
C#
83
star
22

MyTasks

Xamarin.Forms goodlooking UI sample.
C#
75
star
23

xamarin-forms-gui.cs

Xamarin.Forms gui.cs Backend
C#
74
star
24

dotnet-maui-samples

The samples in this repository demonstrate how to use different aspects of .NET MAUI to build cross-platform apps for iOS, Android, macOS and the Windows.
C#
67
star
25

netmaui-carrental-app-challenge

CarRental App UI Challenge made with .NET MAUI.
C#
61
star
26

netmaui-movies-app-challenge

Movies App UI Challenge made with .NET MAUI.
C#
59
star
27

Xamarin.Forms.TabView

The TabView is a Xamarin.Forms control to display a set of tabs and their respective content.
C#
54
star
28

TravellingApp

Xamarin.Forms goodlooking UI sample using the new CarouselView.
C#
54
star
29

DrinksGalleryApp

Xamarin.Forms goodlooking UI sample using the new CarouselView (Parallax).
C#
53
star
30

netmaui-beautyshop-app-challenge

Beautyshop App UI Challenge made with .NET MAUI.
C#
53
star
31

Xamarin.Forms-Samples

Xamarin.Forms Samples!
C#
51
star
32

FocusOnXamarin

NET Conf: Focus on Xamarin samples
C#
49
star
33

xamarin-forms-walkthrough

Mobile App Walkthrough created with Xamarin.Forms
C#
47
star
34

FoodDeliveryAppDuo

Xamarin.Forms good looking UI sample for Surface Duo.
C#
41
star
35

netmaui-surfing-app-challenge

Surfing App UI Challenge made with .NET MAUI.
C#
41
star
36

openaisharp-maui

C# .NET wrapper library to use with OpenAI APIs.
C#
40
star
37

ArtNews

Xamarin.Forms goodlooking UI sample.
C#
38
star
38

TemplateMAUI

A set of .NET MAUI templated controls.
C#
38
star
39

netmaui-skateboard-ecommerce-app-challenge

Skateboard E-commerce App UI Challenge made with .NET MAUI.
C#
36
star
40

ShoppingList

Xamarin.Forms goodlooking UI sample using the new Expander Control.
C#
34
star
41

UAP-Samples

Windows 10 Universal App Platform
C#
34
star
42

netmaui-finance-app-challenge

Finance App UI Challenge made with .NET MAUI.
C#
34
star
43

TimelinePulse

Xamarin.Forms good looking UI sample.
C#
33
star
44

netmauigraphics-chat-app-challenge

Chat App UI Challenge made with .NET MAUI Graphics.
C#
33
star
45

FavFighters

Xamarin.Forms goodlooking UI sample using the new SwipeView.
C#
33
star
46

rive-maui

.NET MAUI runtime for Rive
C#
33
star
47

AvaloniaMauiHybrid.Controls

Easily expose Avalonia drawn controls to use in .NET MAUI.
C#
32
star
48

Events

Events Presentations and Samples
C#
31
star
49

netmaui-travel-app-challenge

Travel App UI Challenge made with .NET MAUI (and Xamarin.Forms).
C#
31
star
50

AlohaKit.Components

Cupertino, Fluent and Material drawn Controls with high performance and 100% customizable.
C#
31
star
51

Xampane

Xamarin Forms Layouts Library
C#
30
star
52

screenshot-to-maui

Convert a screenshot to .NET MAUI XAML code
C#
29
star
53

xamarin-forms-goodlooking-apps

Xamarin.Forms goodlooking UI apps
28
star
54

BindableLayoutPlayground

Xamarin.Forms BindableLayout Playground.
C#
28
star
55

taller-dotnet-maui

Taller de desarrollo de aplicaciones con .NET MAUI
27
star
56

awesome-monodevelop

A curated list of awesome Visual Studio for macOS and MonoDevelop addins, tools and resources.
25
star
57

MyTaxiCompany

Xamarin.Forms Map Application Sample
C#
24
star
58

FlightBookingApp

Xamarin.Forms goodlooking UI sample using the new SwipeView.
C#
24
star
59

netmaui-coupons-app-challenge

Coupons App UI Challenge made with .NET MAUI.
C#
21
star
60

Xamarin.Forms-Gallery

Xamarin.Forms Core Gallery redesign.
C#
20
star
61

netmaui-moon-nft-app-challenge

Moon NFT App UI Challenge made with .NET MAUI.
C#
18
star
62

FormsWPFConverter

Live XAML converter from WPF to Xamarin.Forms Tool
C#
17
star
63

netmaui-mytasks-app-challenge

Tasks App UI Challenge made with .NET MAUI.
C#
17
star
64

FormsGtkToolkit

The Forms Gtk Toolkit is a collection of Controls for Xamarin.Forms GTK Backend.
C#
17
star
65

xamarin-forms-statusbar

Xamarin.Forms Effect to manage the StatusBar BackgroundColor.
C#
16
star
66

XamarinFormsStateTriggers

A collection of custom visual state triggers for Xamarin.Forms
C#
16
star
67

FormsWPFLive

Live XAML development for Xamarin Forms Apps using WPF Backend.
C#
16
star
68

xamarin-forms-entityframework-sample

Xamarin.Forms App using Entity Framework Core 2.0
C#
16
star
69

VS4Mac-SkiaSharpFiddle

SkiaSharp playground VS4Mac addin.
C#
16
star
70

comet-travel-app-challenge

Travel App UI Challenge made with Comet.
C#
14
star
71

Xamarin.Forms.AppBar

An app bar consists of a Xamarin.Forms toolbar.
C#
14
star
72

xamarin-forms-wpf-weather-sample

Xamarin.Forms WPF Backend Weather Sample
C#
14
star
73

xamarin-forms-wpf-samples

Xamarin.Forms WPF Samples
C#
14
star
74

FormsGtkLive

Xamarin Forms GTK Backend Live Preview
C#
14
star
75

netmaui-teenfeel-app-challenge

TeenFeel App UI Challenge made with .NET MAUI.
C#
13
star
76

AvaloniaSkiaSharpFiddle

Avalonia SkiaSharp Fiddle is a SkiaSharp playground created with Avalonia and running on macOS, Linux, Windows and WebAssembly.
C#
13
star
77

DotNet2020

Ways to create controls in Xamarin.Forms
C#
13
star
78

xamarin-forms-gtk-samples

Xamarin.Forms GTK Samples
C#
13
star
79

mvpsummit2022-dotnet-maui

MVP Summit 2022 - .NET MAUI samples
C#
13
star
80

VS4Mac-LottiePlayer

VS4Mac addin to Preview Lottie json files.
C#
12
star
81

xamarin-forms-channel9-sample

Channel 9 Application made with Xamarin.Forms.
C#
12
star
82

xamarin-forms-arcore-sample

Xamarin.Forms ARCore Sample using Wave Engine
C#
12
star
83

dotnet-maui-course-resources

.NET MAUI course
C#
12
star
84

ShapesPlayground

Sample to show how to use Shapes in Xamarin.Forms
C#
11
star
85

alohakit-blazor-prototype

Prototype and test to bring drawn controls from .NET MAUI to Blazor WebAssembly.
HTML
11
star
86

monkeyconf-website

Website project of the Monkey Conf event created using Xamarin.Forms.
C#
11
star
87

RelativeSourcePlayground

Xamarin.Forms RelativeSource sample
C#
10
star
88

flutter-chat-app-challenge

Chat App UI Challenge made with Flutter.
Dart
10
star
89

xamarin-forms-waveengine-sample

Xamarin.Forms Sample using Wave Engine
C#
10
star
90

chatgpt-maui-playground

In this repository there are ChatGPT tests generating code for specific .NET MAUI UI or creating small applications directly.
C#
9
star
91

MonkeyConf2018

Slides and samples from Monkey Conf 2018 event
C#
9
star
92

VS4Mac-AssetStudio

VS4Mac addin with functionality related to assets management.
C#
9
star
93

mvxforms-samples

Xamarin Forms MvvmCross Samples
C#
9
star
94

xamarin-forms-waveengine-ar-sample

Xamarin.Forms Augmented Reality Sample
C#
9
star
95

mauifest2022

MauiFest 2022 es un evento de comunidad online y gratuito para celebrar el lanzamiento de .NET MAUI
9
star
96

OxyPlot-Xamarin.Forms-Sample

OxyPlot Xamarin.Forms Sample
C#
9
star
97

xamarin-forms-ooui-movies-sample

The Movie DB Ooui Xamarin.Forms Sample
C#
8
star
98

AuroraControlsPlayground

Xamarin.Forms sample to show the main Aurora Controls features.
C#
8
star
99

xamarin-forms-gtk-iot-samples

Xamarin.Forms GTK Backend IoT Sample
C#
8
star
100

DotNetAlliance

La DotNet Alliance es una página web que agrupa todos los eventos de las comunidades .NET de España y los muestra en un calendario común.
8
star