78
Advanced Performance & Profiling in Silverlight 4 Seema Ramchandani Program Manager Microsoft Corporation CL02

Advanced Performance & Profiling in Silverlight 4

  • Upload
    lucus

  • View
    30

  • Download
    0

Embed Size (px)

DESCRIPTION

CL02. Advanced Performance & Profiling in Silverlight 4 . Seema Ramchandani Program Manager Microsoft Corporation. Give me a…. Burly CT Scan Churlish Racquetball Curling Brain Boxing Double-Click Espresso Machine Ribbon Accordian Control . Adjective Medical Diagnostic - PowerPoint PPT Presentation

Citation preview

Page 1: Advanced Performance & Profiling in Silverlight 4

Advanced Performance & Profiling in Silverlight 4

Seema RamchandaniProgram ManagerMicrosoft Corporation

CL02

Page 2: Advanced Performance & Profiling in Silverlight 4

1. Adjective2. Medical Diagnostic3. Adjective4. Sport5. 2nd Sport6. Human Organ7. Sport (gerund)8. UI Interaction9. Household Appliance10.UI Element11.2nd UIElement

Give me a…1. Burly 2. CT Scan3. Churlish4. Racquetball5. Curling6. Brain7. Boxing8. Double-Click9. Espresso Machine10. Ribbon11.Accordian Control

Page 3: Advanced Performance & Profiling in Silverlight 4

Why Profile?

1. Burly 2. CT Scan3. Churlish4. Racquetball5. Curling6. Brain7. Boxing8. Double-Click9. Espresso Machine10. Ribbon11.Accordian Control

Page 4: Advanced Performance & Profiling in Silverlight 4

Advanced Performance & Profiling in Silverlight 4

Seema RamchandaniProgram ManagerMicrosoft Corporation

P09-10

Page 5: Advanced Performance & Profiling in Silverlight 4

> Measuring & Profiling> Employing the GPU> Understanding the Layers

Agenda

Page 6: Advanced Performance & Profiling in Silverlight 4

1. Identify potential problem areas> Startup? Memory? Framerate?

2. Monitor as changes are made> Framerate: size of dirty regions

3. Test on a range of hardware

4. Verify that things are as expected

Iteratively measure perf

Page 7: Advanced Performance & Profiling in Silverlight 4
Page 8: Advanced Performance & Profiling in Silverlight 4

Virtualized ListBox?UISpy.exe (as admin)

demo

Page 9: Advanced Performance & Profiling in Silverlight 4
Page 10: Advanced Performance & Profiling in Silverlight 4

33 msec

Frame BasedModel

132msecSilverlight’s Real-TimeAnimation

time

BUSYSkip 3 turns

Page 11: Advanced Performance & Profiling in Silverlight 4

Threads> UI Thread

> User Code> Control Code> Animations> Layout

> Non-UI Thread> Frame

Rasterization> Media Decoding

Page 12: Advanced Performance & Profiling in Silverlight 4

Event Handler

s

Tick

Any property changes

?

Layout

Queue up

rendering

changes

Rasterize in back buffer

Hey browser! Show

my Frame

Page 13: Advanced Performance & Profiling in Silverlight 4

4 Ways to Measure & Profile1. Do the changes impact framerate?

EnableFrameRateCounterMaxFramerate

Page 14: Advanced Performance & Profiling in Silverlight 4
Page 15: Advanced Performance & Profiling in Silverlight 4

4 Ways to Measure & Profile1. Do the changes impact framerate?

EnableFrameRateCounter

2. Visualize the Pain PointsEnableRedrawRegionsEnableCacheVisualization

Page 16: Advanced Performance & Profiling in Silverlight 4

Screen UpdatingWe only draw what is “dirty”,

….as far as we can figure out,

…sometimes we are too sensitive to bindings or property changes.

(You should always double-check.)

Page 17: Advanced Performance & Profiling in Silverlight 4

EnableRedrawRegions<param name="enableRedrawRegions" value="true" />

demo

Page 18: Advanced Performance & Profiling in Silverlight 4
Page 19: Advanced Performance & Profiling in Silverlight 4

4 Ways to Measure & Profile1. Do the changes impact framerate?

EnableFrameRateCounter2. Visualize the Pain Points

EnableRedrawRegions

3. Big Picture: What is the actual diff?Profile: User & Platform CodeVSTS2010 + Silverlight 4 CLR

Page 20: Advanced Performance & Profiling in Silverlight 4

Profile with VSTS 2010

demo Instructions will be posted on http://blogs.msdn.com/seema vsperfclrenv /sampleon

set CORECLR_ENABLE_PROFILING=1set CORECLR_PROFILER=%COR_PROFILER%

vsperfcmd /start:sample /output:myProfile.vspvsperfcmd /launch:"c:\Program Files\Internet Explorer\iexplore.exe“ navigate, play with app, Shut down.vsperfcmd /shutdown

Page 21: Advanced Performance & Profiling in Silverlight 4
Page 22: Advanced Performance & Profiling in Silverlight 4
Page 23: Advanced Performance & Profiling in Silverlight 4

4 Ways to Measure & Profile1. Do the changes impact framerate?

EnableFrameRateCounter2. Visualize Pain Points

EnableRedrawRegions3. Big Picture: What is the actual diff?

Profile: User & Platform Code

4. Profile: Unmanaged Platform CodeVSTS2010 for SL4 or XPerf for SL3

Page 24: Advanced Performance & Profiling in Silverlight 4

Profiling with XPerf> ETW – Event Tracing for Windows

> Tracing mechanism for both user-mode & kernel-mode apps.

> Silverlight & CLR have embedded ETW events.

> Analyzes unmanaged callstack.> Describes CPU cycles over time

Instructions: http://blogs.msdn.com/seema

Page 25: Advanced Performance & Profiling in Silverlight 4

Demo ListBox in SW / HWProfile Instructions:http://blogs.msdn.com/seema --> search “xperf”demo

Page 26: Advanced Performance & Profiling in Silverlight 4

ListBox: Software vs. Hardware

Page 27: Advanced Performance & Profiling in Silverlight 4

> Measuring & Profiling> Employing the GPU> Understanding the Layers

Agenda

Page 28: Advanced Performance & Profiling in Silverlight 4

Let’s define “software” and “hardware”

Page 29: Advanced Performance & Profiling in Silverlight 4

How we draw1. ParentNode2. Layout Offset (internal LayoutTransform)3. RenderTransform4. Clip5. Opacity6. OpacityMask7. Children

Page 30: Advanced Performance & Profiling in Silverlight 4

How we draw1. ParentNode2. Layout Offset (internal LayoutTransform)3. RenderTransform4. Perspective5. Clip6. Effect7. Opacity8. OpacityMask9. Children

Page 31: Advanced Performance & Profiling in Silverlight 4
Page 32: Advanced Performance & Profiling in Silverlight 4

Intermediate surface

Apply Effect

Page 33: Advanced Performance & Profiling in Silverlight 4

Features that use RenderToIntermediate

> WriteableBitmap> Effects> Projection> GPU Caching

Page 34: Advanced Performance & Profiling in Silverlight 4

Video card

+

Page 35: Advanced Performance & Profiling in Silverlight 4

: Strengths+

BitBlt

ScaleTransforms

TranslateTransformsRotateTransforms

…and so much more, but let’s just start with these…

Blending

Page 36: Advanced Performance & Profiling in Silverlight 4

1. ParentNode2. Layout Offset3. RenderTransfor

m4. Perspective5. Clip6. Effect7. Opacity8. OpacityMask9. Hardware Cache10.Children

Page 37: Advanced Performance & Profiling in Silverlight 4
Page 38: Advanced Performance & Profiling in Silverlight 4

Effect GPU Cache

Opacity

Rect Clip

Render Trans

Layout Offset

Parent Node

Opac Mask Opac Effect Clip Persp

TransRend Trans

Layout

Offset

Parent

Node

Child

CPU

GPU

OR

CPU

Page 39: Advanced Performance & Profiling in Silverlight 4

Effect GPU Cache

Opacity

Rect Clip

Render Trans

Layout Offset

Parent Node

Opac Mask Opac Effect Clip Persp

TransRend Trans

Layout

Offset

Parent

Node

Child

CPU

GPU

OR

CPU

Page 40: Advanced Performance & Profiling in Silverlight 4

Hardware Acceleration> Plugin Setting EnableGPUAcceleration

> UIElement.CacheMode=BitmapCache> API: “Cache” this element as a bitmap.> Behavior: GPU handles Transforms*, Blends, and

Clips.> Ex: GPU handles Media shrink or stretch

> Support:> Windows: Browser & Fullscreen (all DX9.0c drivers)> Mac: Fullscreen

Page 41: Advanced Performance & Profiling in Silverlight 4

Where to set BitmapCache?> Animated Properties but Static Content

> Transform, Opacity, or Clip> No “SW-only properties” on self or parent

> Take care of your visual tree order.> Minimal Interleaving> No Nesting of Cached nodes

Page 42: Advanced Performance & Profiling in Silverlight 4
Page 43: Advanced Performance & Profiling in Silverlight 4

Background, is auto-cached with EnableGPUAcceleration

Page 44: Advanced Performance & Profiling in Silverlight 4

Static, included in background

Page 45: Advanced Performance & Profiling in Silverlight 4

Dynamic – Animating Translation CacheMode = BitmapCache

Dynamic – Animating Translation CacheMode = BitmapCache

Static

Page 46: Advanced Performance & Profiling in Silverlight 4

StaticDynamic – Cached

Dynamic – Cached

DynamicDo Not Cache

Page 47: Advanced Performance & Profiling in Silverlight 4

<Canvas> <Canvas.Background><!--Insert Kitty--> </> <Humpty Loaded="Play" /> <Seahorse /> <!-- Animated Seahorses --> <Seahorse Loaded="Move" CacheMode="BitmapCache" /> <Seahorse Loaded="Move" CacheMode="BitmapCache" /></Canvas>

Z-Order

Page 48: Advanced Performance & Profiling in Silverlight 4

Grid

Humpty Seahorse Seahorse Seahorse

ImageBrush

+ +

Intermediate for background

2 cached nodes

Z-Order

Page 49: Advanced Performance & Profiling in Silverlight 4

<Canvas> <Canvas.Background><!--Insert Kitty--> </> <Humpty Loaded="Fall" /> <Seahorse /> <!-- Animated Seahorses --> <Seahorse Loaded="Move" CacheMode="BitmapCache" /> <Seahorse Loaded="Move" CacheMode="BitmapCache" /></Canvas>

Z-Order

Page 50: Advanced Performance & Profiling in Silverlight 4

<Canvas> <Canvas.Background><!--Insert Kitty--> </> <Seahorse /> <!-- Animated Seahorses --> <Seahorse Loaded="Move" CacheMode="BitmapCache" /> <Humpty Loaded="Fall" /> <Seahorse Loaded="Move" CacheMode="BitmapCache" /></Canvas>

Z-Order

Page 51: Advanced Performance & Profiling in Silverlight 4

<Canvas> <Canvas.Background><!--Insert Kitty--> </> <Seahorse /> <!-- Animated Seahorses --> <Seahorse Loaded="Move" CacheMode="BitmapCache" /> <Humpty Loaded="Fall" CacheMode="None" /> <Seahorse Loaded="Move" CacheMode="BitmapCache" /></Canvas>

Z-Order

Page 52: Advanced Performance & Profiling in Silverlight 4

Grid

Seahorse Seahorse Humpty Seahorse

ImageBrush

+Cached node

+Cached node

+

Intermediate TextureIntermediate for background

Z-Order

Page 53: Advanced Performance & Profiling in Silverlight 4

Calvin & Hobbes

demo

Page 54: Advanced Performance & Profiling in Silverlight 4

More Practical uses> Media

Page 55: Advanced Performance & Profiling in Silverlight 4

Decode

YUV Conve

rt

Resize

(opt)Blend (opt) Draw

Rinse & Repeat, at the video framerate

Media: Every Pixel, Every frame.

> Encode at the minimum framerate possible.

> Encode at the desired size.> Blending with media is expensive.

Page 56: Advanced Performance & Profiling in Silverlight 4

More Practical uses> Media

Background(Final Buffer)

Cached Media Element

Top Level Stuff++

Page 57: Advanced Performance & Profiling in Silverlight 4

Enhancing media with GPU > Is the MediaElement doing any of

these?> Stretching> Rectangular clip> Blending via Opacity

> If so, then:> Plugin: EnableGPUAcceleration=true> MediaElement: CacheMode=BitmapCache> Debug:

EnableFrameRateCounterEnableCacheVisualization

> Profile: XPerf

Page 58: Advanced Performance & Profiling in Silverlight 4

Profiled on my own machines360p Silverlight H264 Video, Stretched to FS

CPU w/ SW Stretch

CPU w/ HW Stretch

% Diff

XP laptop ’041.3ghz single core

70% CPU 32% CPU -55%

Vista desktop ’04 2.4g single core

88% CPU 44% CPU -50%

Vista laptop ’072.3g core2duo

60% CPU 24% CPU -60%

540p Silverlight H264 Video, Stretched to FS

SW Stretch HW Stretch % Diff

XP laptop ’041.3ghz single core

69% CPU 59% CPU -15%

Vista laptop ’072.3g core2duo

71% CPU 37% CPU -47%

Page 59: Advanced Performance & Profiling in Silverlight 4

More Practical uses> Media

> Transitions: > Zoom in/out> Sliding in> Blending in

> Special Uses of Controls> ListBox from earlier

Page 60: Advanced Performance & Profiling in Silverlight 4

ListBox: Can I use Hardware?> Key concern: Scrolling> Knew my tree above and below

> Static content> Parent has neither effects

nor perspective, etc

> Changing HW-friendly properties:> Translation & Rectangular Clipping

> Knew explicit size> Smaller than Max Texture Size (~2048 in either direction)

Page 61: Advanced Performance & Profiling in Silverlight 4

ListBox: What changed with Hardware?> Scrolling is done by HW

> Text is not recalculated every frame> Faster> Uglier.

One can switch back to un-cached dynamically.

Page 62: Advanced Performance & Profiling in Silverlight 4
Page 63: Advanced Performance & Profiling in Silverlight 4

Know the road> Watch VRAM usage

> Note: SL4 Beta bug

> Watch your tree structure

> Ensure there is a positive impact> Use XPerf, F1, etc> Blts can be more expensive than a simple

transform

Page 64: Advanced Performance & Profiling in Silverlight 4

Decision tree for HW

visio ftw.

Page 65: Advanced Performance & Profiling in Silverlight 4

EnableCacheVisualization

> Draws HW surfaces with normal colors.

> Tints SW surfaces

Page 66: Advanced Performance & Profiling in Silverlight 4

> Measuring & Profiling> Employing the GPU> Understanding the Layers

Agenda

Page 67: Advanced Performance & Profiling in Silverlight 4

1. ParentNode2. Layout Offset3. RenderTransfor

m4. Perspective5. Clip6. Effect7. Opacity8. OpacityMask9. Children

Page 68: Advanced Performance & Profiling in Silverlight 4

Minimize Size of affected objects

Vs.

Page 69: Advanced Performance & Profiling in Silverlight 4

Rendering:Minimize Number of operations per frame> Opacity, OpacityMask, Clipping,

Perspective, Effects, etc

Vs.

HelloWorld

Hello

World

Page 70: Advanced Performance & Profiling in Silverlight 4

Rendering:Minimize Number of frames

Vs.

Page 71: Advanced Performance & Profiling in Silverlight 4

http://www.newyorker.com/images/2008/05/26/p233/080526_r17431_p233.jpg

Page 72: Advanced Performance & Profiling in Silverlight 4

…Ashraf, our gfx architect, covers the graphics pipelines in depth…

Author: Ashraf MichailPublisher: Addison-Wesley

Page 73: Advanced Performance & Profiling in Silverlight 4

Fill out Survey

PDC gives

$1

Page 74: Advanced Performance & Profiling in Silverlight 4

http://blogs.msdn.com/seema

Q&A

Page 75: Advanced Performance & Profiling in Silverlight 4

YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation

forms online atMicrosoftPDC.com

Page 76: Advanced Performance & Profiling in Silverlight 4

Learn More On Channel 9> Expand your PDC experience through

Channel 9

> Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses

channel9.msdn.com/learnBuilt by Developers for Developers….

Page 77: Advanced Performance & Profiling in Silverlight 4

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 78: Advanced Performance & Profiling in Silverlight 4