You are on page 1of 29

7/29/2019

Rakesh VM
IBU| NeST |Technopark

1
2 7/29/2019

2D Graphics.

WPF Performance Concerns

Asynchronous Programming
and Multithreading

Performance Profiling
GDI VS WPF
Feature Windows Forms (using GDI/GDI+) WPF

System.dll WindowsBase.dll
DLLs used System.Drawing.dll PresentationCore.dll
System.Windows.Forms.dll PresentationFoundation.dll
Windows Many windows One window

Units Hardware pixels Device-independent unit (1/96-inch)

Control positioning Absolute Absolute, Dynamic, Data-bound

Closely spaced rows of dots (raster- Mathematical equations (vector-


Image is formed by
based) based)

Rendering engine DirectShow DirectX (Direct3D) Media Foundation

Retained - the application keeps the


Immediate - the application repaints
Mode drawing information and the system
the area that becomes invalidated
does the repainting

Rendering performed from back to


Clipping: bounds determined and
Painting front: components paint over each
painting occurs there
other

Appropriate pen or brush provided


Pen and brush Current pen and current brush
with each drawing call

Painting region Minimize the region to be painted Do not need to minimize

Events Events RoutedEvents


Requires a player like Windows
Video and Audio Built-in support
Media Player

7/29/2019 3
4 7/29/2019

2D Graphics

Allow for full


scalability
Resolution
independence
Coordinates
are doubles in
WPF instead of
integers
Y-axis points
down, X-axis
points right

(0,0) is top
left of
coordinate
space
5 7/29/2019

2D Graphics
2D Graphics

Brushes

Drawings

Geometries

Images

Shapes
6 7/29/2019

Brushes

Brush

SolidColorBrus LinearGradient RadialGradient


DrawingBrush Visual Brush
h Brush Brush
7 7/29/2019
8 7/29/2019

A drawing object describes


What Is a visible content, such as a
shape, bitmap, video, or a line
Drawing of text.
Object? Different
describe
types of drawings
different types of
content. Such as shape,
Image.
9 7/29/2019

Geometry
LineGeo
metry

Geometry

Rectangl
EllipseGe
eGeome
ometry
try
10 7/29/2019

Shape

Shape

Ellipse

Line

Path

Polygon

Polyline

Rectangle.
11 7/29/2019

The Canvas is the


most basic layout
panel in WPF.

It's child elements


are positioned by
explicit
coordinates.

The coordinates
can be specified
relative to any
side of the panel.

Canvas.Left,
Canvas.Top,
Canvas.Bottom
and Canvas.Right
are attached
properties
12 7/29/2019

Canvas.
Images.
Geometries.
Shapes.
Brushes.
WPF Performance Concerns

13
14 7/29/2019

UI Software
Virtualization Rendering

Resource Freezable
Performance
Optimizations
15 7/29/2019

UI Virtualization

•VirtualizingStackPanel.

Enable IsVirtualizing="True“

virtualization •VirtualizingStackPanel.
VirtualizationMode="Rec

for all ycling"

containers •ScrollViewer.
IsDeferredScrollingEnabl
ed="True“.
16 7/29/2019

Use the default theme


Dynamic vs. Static
Sharing Resources of the control for
Resources
resources.

Sharing resources Dynamic resources


Resources in Static resources are
significantly reduces are resolved each
Application or resolved during
the number of time they are
Window scope parsing
objects. accessed.
17 7/29/2019

WPF defines
three tiers

0 = No hardware
acceleration.
DirectX version
level < 7.0

1 = Partial
hardware
acceleration.
DirectX version
level [7.0, 9.0)

2 = Most features
use hardware
acceleration.
DirectX version
level >= 9.0
18 7/29/2019

Some things • BitmapEffects


that can cause • Tiling
your app to • Layered windows
(hardware accelerated
fallback to in WPF 3.5)
software • AllowsTransparency=“Tr
ue”
rendering

Demo
19 7/29/2019

A WPF object When unfrozen the object behaves like any other object
that has a
frozen and
an unfrozen When frozen the object cannot be modified
state.

When the object is frozen the WPF graphics system no longer needs to
spend resources monitoring the object for changes.
Opt-out of
change
notifications

Examples Brush

Transform

Geometry
20 7/29/2019

Freezables
Software
Rendering
Rendering
Tiers
Resource
Performance
UI Optimizations
Virtualization
21 7/29/2019

Asynchronous Programming and Multithreading

•They belongs to particular thread.


Many WPF objects have Thread affinity.

•The base object


Dispatcher Object

•Invoke
The Dispatcher •BeginInvoke

•Status of current operation


DispatcherOperation

•Priority to the operation


DispatcherPriority
22 7/29/2019

Some tips for higher performance


Dispatch expensive calls.

Fix binding errors.

Reduce the number of visuals.

Prevent Software Rendering.

Load resources when needed.

Virtualize lists and views.

Enable Container Recycling.

Freeze Freezables.

Disable Assembly localization.

Lower the framerate of animations.

Use StreamGeometries instead of PathGeometries.


23 7/29/2019

Backgroundworker
DoWork ()
•Start execution in different
thread.
•Don’t update the UI Controls

CancelAsync() ProgressChanged ()
•Request thread cancellation. •Event that can use for updating the
•CancellationPending Flag used to UI
determine the thread is stop
requested

RunWorkerCompleted ()
•On completion of thread execution
24 7/29/2019

Tools for fine tuning

RedGate JetBrains' Visual


Perforator
ANTS dotTrace Profiler

Performance Memory
profiler profiler
25 7/29/2019

WPF
4.5
26 7/29/2019

Ribbon control

Improved performance when displaying large sets of grouped data

New features for the VirtualizingPanel

Binding to static properties

Accessing collections on non-UI Threads

Synchronously and Asynchronously validating data

Automatically updating the source of a data binding

Binding to types that Implement ICustomTypeProvider

Retrieving data binding information from a binding expression

Checking for a valid DataContext object

Repositioning data as the data's values change (Live shaping)

Improved Support for Establishing a Weak Reference to an Event

New methods for the Dispatcher class

Markup Extensions for Events


27 7/29/2019

Reference

http://msdn.microsoft.com/en-us/library/bb613588(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/ms754130.aspx

http://msdn.microsoft.com/en-us/library/aa970683.aspx
28 7/29/2019
For queries:-
rakesh.vm@nestgroup.net
7/29/2019
IBU| NeST |Technopark

29

You might also like