Compiled Xaml Performance in

  • View
    45

  • Download
    1

Embed Size (px)

Text of Compiled Xaml Performance in

Compiled Xaml in Xamarin.Forms

Hi, Im MattMaking stuff with Xamarin since 13

The mobile guy at

I build MFractor to make your job easier :)

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Overview

Session OverviewXamarin.Forms ArchitectureXaml overviewWhat is Compiled Xaml?Using Compiled Xaml.Benchmarking a Xamarin.Forms AppBenchmarking AnalysisSummary

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Xamarin.Forms Architecture

Cross platform mobile solutionTypically MVVM DesignModel -> Data entitiesView -> Visual code (Xaml)ViewModel -> Application state

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

What is Xaml?A view markup languageFancy xmleXtensible Application Markup LanguageDeveloped by Microsoft as an hierarchical object creation languageDefines visual content of page or view.

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Credit: James Montemagno

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Xaml Flavours

Non-compiled (Inflated):Embedded into assemblyBloat assembly size.Inflated at runtimeWithin InitializeComponentLoadFromXamlCompiled:Xaml is converted into ILMuch faster view creation.*.xaml removed from final assemblyReduced assembly size.

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

App Wide:Using Compiled Xaml

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Skipping views:Using Compiled Xaml

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

XamlC build task runs over assemblyReweavingInspects for XamlCompilation attributesAssembly wideView levelSkipParses *xamlInitiliseComponent replaced with IL codeOptimise new IL code Strip out *.xamlUsing Compiled Xaml

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Using Compiled Xaml

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

ProsSignificantly faster view creationSome runtime errors are now compile time errorsConsIncreased build timesSome issues with resource dictionary.Undocumented(?) restrictions that corrupt the generated ILResolve by replacing with x:Static expressionsBinding errors are still runtimePros - Cons

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Performance Analysis

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

MethodologyTested Xaml Samples apphttps://github.com/matthewrdev/xamarin-samples/tree/master/compiled-xaml-benchmarkingProfile the startup time of a viewWrap InitialiseComponent in a profilerLog with non-blocking loggerRecord time in milliseconds for 3 screensOpen each screen 3 timesUsing 4 different devicesiOS SimulatoriPhone SELenovo Android TabletGenymotion Android N Emulator

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Inflated Xaml ResultsHome PageGrid PageKeypad PageIOS Simulator126ms6.33ms8msiPhone SE103ms48.66ms79.33msLenovo1030.33ms87.33ms145.66msGenymotion170ms9.33ms10.33ms

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Compiled Xaml ResultsHome PageGrid PageKeypad PageIOS Simulator21ms3.00ms2.33msiPhone SE26.33ms11.66ms14.66msLenovo185.33ms11.33ms51.66msGenymotion38ms1.34ms6.67ms

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Startup page is always most expensiveMore x:Static == less startup timeLess dynamic bindings = less startup timeResource Dictionaries can cause runtime errors. Observations

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Results SummaryCompiled Xaml is 20% as expensive as inflated xaml.Build time increase for compiled xaml15s for 40 xaml projectAndroid AOT Compilation provides further improvements:2% at huge build time cost. +100s for moderate sized appSubsequent view creations come at reduced costCompiled -> 10% of initial timeInflated -> 50% of initial timeSpikes in creation time:Coincided with dalvik GC cycleCoincided with nursery promotionCould be optimized by changing nursery and collection thresholds

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

ResourcesXaml Samples Source CodePerformance Benchmarking DataXaml BasicsXamarin Forms Source Code

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com

Questions?

@matthewrdev | matthew.ch.robbins@gmail.com | 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?

@matthewrdev | matthew.ch.robbins@gmail.com | mfractor.com