compiled xaml performance in xamarin.forms

26
Compiled Xaml in Xamarin.Forms

Upload: matthew-robbins

Post on 10-Feb-2017

62 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Compiled Xaml Performance in Xamarin.Forms

Compiled Xaml in Xamarin.Forms

Page 2: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Hi, I’m Matt➔Making stuff with Xamarin since ‘13

➔ The mobile guy at

➔ I build MFractor to make your job easier :)

Page 3: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Overview➔ Session Overview

◆ Xamarin.Forms Architecture

◆ Xaml overview

◆ What is Compiled Xaml?

◆ Using Compiled Xaml.

◆ Benchmarking a Xamarin.Forms App

◆ Benchmarking Analysis

◆ Summary

Page 4: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Xamarin.Forms Architecture➔ Cross platform mobile solution

➔ Typically MVVM Design

◆ Model -> Data entities

◆ View -> Visual code (Xaml)

◆ ViewModel -> Application state

Page 5: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Page 6: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

What is Xaml?➔A view markup language

◆ Fancy xml

◆ “eXtensible Application Markup Language”

◆ Developed by Microsoft as an hierarchical object creation language

◆ Defines visual content of page or view.

Page 7: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Credit: James Montemagno

Page 8: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Xaml Flavours➔Non-compiled (Inflated):

◆ Embedded into assembly

● Bloat assembly size.

◆ Inflated at runtime

● Within “InitializeComponent”

● “LoadFromXaml”

➔ Compiled:

◆ Xaml is converted into IL

● Much faster view creation.

◆ *.xaml removed from final assembly

● Reduced assembly size.

Page 9: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

➔App Wide:

Using Compiled Xaml

Page 10: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

➔ Skipping views:

Using Compiled Xaml

Page 11: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

➔ XamlC build task runs over assembly

◆ “Reweaving”

➔ Inspects for XamlCompilation attributes

◆ Assembly wide

◆ View level

◆ Skip

➔ Parses *xaml

➔ InitiliseComponent replaced with IL code

➔Optimise new IL code

➔ Strip out *.xaml

Using Compiled Xaml

Page 12: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Using Compiled Xaml

Page 13: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

➔ Pros

◆ Significantly faster view creation

◆ Some runtime errors are now compile time errors

➔ Cons

◆ Increased build times

◆ Some issues with resource dictionary.

● Undocumented(?) restrictions that corrupt the generated IL

● Resolve by replacing with x:Static expressions

◆ Binding errors are still runtime

Pros - Cons

Page 14: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Performance Analysis

Page 15: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Methodology➔ Tested “Xaml Samples” app

◆ https://github.com/matthewrdev/xamarin-samples/tree/master/compiled-xaml-benchmarking

➔ Profile the startup time of a view

◆ Wrap InitialiseComponent in a profiler

◆ Log with non-blocking logger

◆ Record time in milliseconds for 3 screens

◆ Open each screen 3 times

◆ Using 4 different devices

● iOS Simulator

● iPhone SE

● Lenovo Android Tablet

● Genymotion Android N Emulator

Page 16: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Page 17: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Page 18: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Inflated Xaml Results

Home Page Grid Page Keypad Page

IOS Simulator 126ms 6.33ms 8ms

iPhone SE 103ms 48.66ms 79.33ms

Lenovo 1030.33ms 87.33ms 145.66ms

Genymotion 170ms 9.33ms 10.33ms

Page 19: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Compiled Xaml Results

Home Page Grid Page Keypad Page

IOS Simulator 21ms 3.00ms 2.33ms

iPhone SE 26.33ms 11.66ms 14.66ms

Lenovo 185.33ms 11.33ms 51.66ms

Genymotion 38ms 1.34ms 6.67ms

Page 20: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Page 21: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Page 22: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

➔ Startup page is always most expensive

➔More x:Static == less startup time

➔ Less dynamic bindings = less startup time

➔ Resource Dictionaries can cause runtime errors.

Observations

Page 23: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Results Summary➔ Compiled Xaml is 20% as expensive as inflated xaml.

➔ Build time increase for compiled xaml

● 15s for 40 xaml project

➔Android AOT Compilation provides further improvements:

◆ 2% at huge build time cost.

◆ +100s for moderate sized app

➔ Subsequent view creations come at reduced cost

◆ Compiled -> 10% of initial time

◆ Inflated -> 50% of initial time

➔ Spikes in creation time:

◆ Coincided with dalvik GC cycle

◆ Coincided with nursery promotion

◆ Could be optimized by changing nursery and collection thresholds

Page 25: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Questions?

Page 26: Compiled Xaml Performance in Xamarin.Forms

@matthewrdev | [email protected] | mfractor.com

Future Talks?What do you want next?

● Revised Android Network Security talk?

● Dissection of a Xamarin.Android apk?

● Building a Xamarin Studio addin?

● FFImageLoading in Xamarin.Forms?