Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Performance Tips For Metro Style XAML Apps

Performance Tips For Metro Style XAML Apps

This item in japanese

Microsoft has published a paper named “Performance Tips For Metro Style XAML Apps”. This includes several suggestions for remaining responsive, ensuring fluid animations, improving startup time, consuming lesser resources and more. We present a summary here.

UI related -

Animations -

  • Let Animations be independent (of the UI thread) wherever possible
  • Minimize overdraw – for e.g. by collapsing completely obscured elements, using composite elements instead of layering objects
  • Use ‘CacheMode’ for caching a canvas if the elements don’t change/animate
  • Avoid Animating Web View

Startup times -

  • Improve perception by using Splash Screens, Loading pages, background loading of data
  • Minimize XAML to be parsed at startup
  • Optimize Element Count
  • If it does not make much difference, combine assemblies – loading one large assembly typically takes lesser time than loading two small ones

App Process Lifetime -

  • Suspend before termination – an app has upto 5 seconds to save it’s data on suspending before it is terminated.
  • Serialize and de-serialize only data that has changed
  • Free as much memory as possible on suspension and release handles to files and devices. However also design to resume quickly
  • Reuse brushes between pages by creating them as ResourceDictionary elements – this can improve caching

Displaying Data -

  • Use UI virtualization i.e. create only those objects that are near to the view port, and Data virtualization i.e. read large data sets in small increments as and when needed
  • Use Item template selectors

Media -

  • Use full screen playback when possible
  • Don’t overlay embedded video
  • Delay setting the source of the MediaElement
  • Match Video/Image resolution with device resolution if possible
  • For Windows 8, Microsoft recommends H.264 video as the primary video format and AAC and MP3 as the preferred audio formats. Use WAV when including short audio effects (such as in games)

The paper by Microsoft contains detailed explanation with code samples. There is a separate article on DirectX and XAML interop which is not covered in this paper. 

Rate this Article