Compiled Xaml Performance in Xamarin.Forms
-
Upload
matthew-robbins -
Category
Software
-
view
55 -
download
1
Transcript of Compiled Xaml Performance in Xamarin.Forms
Compiled Xaml 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 :)
@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
@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
@matthewrdev | [email protected] | mfractor.com
@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.
@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.
@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
@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
@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
@matthewrdev | [email protected] | mfractor.com
@matthewrdev | [email protected] | mfractor.com
@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
@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
@matthewrdev | [email protected] | mfractor.com
@matthewrdev | [email protected] | mfractor.com
@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
@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
@matthewrdev | [email protected] | mfractor.com
Resources➔ Xaml Samples Source Code
➔ Performance Benchmarking Data
➔ Xaml Basics
➔ Xamarin Forms Source Code
@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?