210 likes | 230 Views
Enhance your UWP app performance with tips on lazy loading, image optimizations, effects, lights, and smart creation techniques. Learn about Relative Size and Offset in the Visual Layer. Explore Adaptive Lights and Effects for Creator's Update. Discover benefits of Visual Layer's Relative Sizing and Offset adjustments. Find demos and call-to-action steps for further learning. Improve your UI practices for a more efficient user experience.
E N D
Tips and Tricks for Creating Performant UI in UWP David Li, Program Manager Robert Mikhayelyan, Software Engineer P4173
Tips and Tricks • Images and Lazy Loading • Lazy Loading with x:Load • Image Loading Optimizations • LoadedImageSurface • Effects, Lights, and Capabilities • Smart Creation of Lights and Effects • Composition Capabilities • Battery Saver • Relative Size / Offset in the Visual Layer • RelativeSize Adjustment • RelativeOffset Adjustment
Loading Hidden Content with x:Load • Before: Setting visibility hidden on groups of visual content • Expensive, especially if some content never gets loaded • All the cost is paid upfront when the app is first launched and loaded • After: x:Load • A replacement for x:DeferLoadStrategy • Defer elements that are not visible in the first frame • For ListView scenarios, use x:Bind and x:Phase to increase scrolling performance • Reduction of Visual Tree Size • You don’t pay the cost for creating elements until the user needs them • Turn on UI Analysis in VS to see where this might be helpful
Some refreshers on XAML image practices • Ideally use vector graphics when possible to avoid adding multiple large image assets to your project • SVGs are now supported for the Creator’s Update • When loading bitmap images, remember to specify the decode pixel width and decode pixel height • In lists and grids, remember x:Phase – prioritize loading of most important content first
Loaded Image Surface • Now takes much less code, and it’s optimized for speed • No need to handle device lost, and XAML handles caching and integration of PLM for you for freeing up video memory while app is suspended • Avoid creating a second D3D device and associated memory overhead
Adaptive Lights and Effects • New XAML Effects and Lights in Creator’s Update • OnConnected and OnDisconnected overrides should be used for creating and disposing Composition objects • When it comes to blur, lights, and shadows – less is more • Blur, spotlights, and animated masked shadows are powerful effects that can have power and performance implications if overused • Composition Capabilities APIs for hardware that do not support the most powerful effects • Power Management and Energy Saver Status APIs for tailoring brushes / effects experience for users who might want to save battery
Visual Layer: Relative Sizing and Offset • For those working in the Visual Layer, we’ve introduced RelativeSizeAdjustment and RelativeOffsetAdjustment • These APIs add the ability to more easily arrange Visuals • Benefits: • Easier to code than manually handling size changed • Faster – an optimized solution that directly targets the pattern we see of developers using expressions to handle layout • More responsive as the resizing happens on the system level • Avoid creation of Expression Animation objects for simple scenarios
Tips and Tricks • Images and Lazy Loading • Lazy Loading with x:Load • Image Loading Optimizations • LoadedImageSurface • Effects, Lights, and Capabilities • Smart Creation of Lights and Effects • Composition Capabilities • Battery Saver • Relative Size / Offset in the Visual Layer • RelativeSize Adjustment • RelativeOffset Adjustment
Call to action • Tweet us your awesome and performant UI creations @WindowsUI • Play with the sample code on our GitHub repository • Re-visit Build session recordings on Channel 9 • Continue your education atMicrosoft Virtual Academy online #MSBuild
Related Content • BUILD 2017 Talks • B8037: Explore the next generation of innovative UI in the Visual Layer • B8100: What’s new and coming for Windows UI: XAML and composition • P4078: Vector Iconography: Using SVG images in your app • Performance articles on Windows Dev Center • Includes content on optimizing background activity, ListView / GridView optimizations, keeping UI thread responsive, optimizing layout, and more • Optimizing your xaml app for performance (10 by 10) #MSBuild