SlideShare a Scribd company logo
1 of 40
Tamir Khason
Software consulter
mPrest systems
: . . .http //blogs microsoft co il/blogs/tamir
Think in terms of scenario
Don’t push to the limit
Do only what you have to do
Set your final goals
Target customer’s expectations
Don’t try to do things “smarter”
WPF is managed code
Don’t forget about memory
Do as little as possible on startup
WPF is retained system
You have no pixels, you have a tree
Minimize trees, keep changes locally
DependencyDependency
ObjectObject
VisualVisual
UIElementUIElement
Framework ElementFramework Element
ControlControl
ShapeShape
FreezableFreezable
AnimatableAnimatable
DrawingDrawingGeometryGeometry
Style, Resources, Binding, PropertiesStyle, Resources, Binding, Properties
TemplatesTemplates
AnimationAnimation
Transformation, Bounds, ClipTransformation, Bounds, Clip
Input, Focus, Layout, Routed EventsInput, Focus, Layout, Routed Events
Change notifications, multithreadingChange notifications, multithreading
Rendering threadRendering thread – mostly GPU,
unmanaged
Part of tree to render, PROBLEMS
(which hard to detect)
UI threadUI thread - CPU only, managed
All services, your code, tree,
PROBLEMS
Bitmap Effects
RenderTargetBitmap
Tilebrush
Operations requires more RAM, then
available in video card
Layered windows
Your code is running here
It runs in CPU only
Visual tree is living here
Most of your performance
problems are here!
Use smaller Visual Tree
Don’t force unnecessary
measurements
Virtualize your data
Use static resources
Move your code into other thread
Create your own other UI threads
FrameworkElement is not base class
Shapes vs. Drawing
Polyline vs. StreamGeometry
Not every “control” is control
Each TextBox contains 30 elements
Each Label contains 5 elements
Each TextBlock contains only one
Use TextBlock
Use TextFormatter
Or even GlyphRuns directly
TextBlock is 32 times faster then
FlowDocument
Use fewer elements, everything in
WPF have costs
Label = 3 X 5 = 15Label = 3 X 5 = 15
Grid = LayoutGrid = Layout
ViewBox = Layout +ViewBox = Layout +
MeasurementsMeasurements
ListBox is too complicated forListBox is too complicated for
such layoutsuch layout
VirtualizingStackPanel is 70xVirtualizingStackPanel is 70x
faster, then StackPanelfaster, then StackPanel
ScrollViewer ScrollBarVisibility = Auto
Don’t calculate nothing
Don’t tickle Layout Engine
FrameworkElement Width/Height= Auto
Don’t you know the real size of content? Resize = layout = tree
walk
Why to measure?
GridLength.Star, ResizeMode, SizeToContent
Want dynamic behavior – do it, but not too much
Make sure, it’s absolutely necessary
Canvas in the smallest content control – it much smaller,
then Grid
More rows and columns means bigger tree
Custom cell template = more then 60 FrameworkElements
Instantiate on demand
VirtualizingStackPanel is 70x faster,
then StackPanel
You can virtualize data by yourself
Virtualization does delete and create
tree – measure before implementing
StaticResource vs. DynamicResource
StaticResource = one evaluation
DynamicResource = one reference
Use ResourceDictionary to share resources
You can Load and Unload resources on
demand
Scale your images
Freeze whenever you can
IList vs. IEnumerable
XML vs. CLR
SelectedIndex calls to IndexOf
Set DataContext instead XAML and
switch it on Application.OnActivated
DependencyProperty is x3 faster, then
INotifyPropertyChanged
ICustomPropertyDescriptor is your friend for
vary property set
ObservableCollection<T> is x90 faster
accesses single item, then List<T>
ObjectDataProvider is x20 smaller, then
XmlDataProvider
<ObjectDataProvider x:Key="cars"
ObjectType="{x:Type l:Cars}"
IsAsynchronous="True“/>
…
<Canvas
DataContext="{StaticResource cars}“>
<Image
Width="1024" Height="768"
Source="{Binding Path=BigImage,
Mode=OneWay,
NotifyOnTargetUpdated=True}"
RenderOptions.CachingHint="Cache"
RenderOptions.BitmapScalingMode="LowQuality">
</Canvas>
It’s asynchronousIt’s asynchronous
It applies everywhere onlyIt applies everywhere only
onceonce
It’s manual and one wayIt’s manual and one way
And saves a lotAnd saves a lot
of unmanagedof unmanaged
resourcesresources
public class Car : DependencyObject
public static readonly DependencyProperty BigImageProperty;
FrameworkPropertyMetadata(
default(BitmapSource),
FrameworkPropertyMetadataOptions.None));
public class Cars : ObservableCollection<Car>
Setter is slower, but getter isSetter is slower, but getter is
much fastermuch faster
This property does notThis property does not
affects neitheraffects neither
measurement, normeasurement, nor
renderingrendering
It’s much better to add andIt’s much better to add and
remove items withoutremove items without
regeneration controlregeneration control
DispatcherOperation oper =
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background, LoadFromXML);
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
(SendOrPostCallback)delegate(object o)
{ CreateCarNode (o); }, node)
BitmapImage image;
image. DecodePixelWidth = 200;
image.Freeze();
Invoke time consumingInvoke time consuming
operations asynchronouslyoperations asynchronously
with low prioritywith low priority
Invoke recent and fast operationsInvoke recent and fast operations
asynchronously with low priorityasynchronously with low priority
Scale and freeze unmanaged and staticScale and freeze unmanaged and static
resourcesresources
ColdStart - After reboot or long period of
time
Resources are not presents
System calls (registry, disk)
WormStart
CLR components are already loaded
Resources are allocated
Tier 0Tier 0 Tier 1Tier 1 Tier 2Tier 2
DX < 7DX < 7 7 <= DX < 97 <= DX < 9
Video RAM >= 30MBVideo RAM >= 30MB
Pixel Shader >= 1.0Pixel Shader >= 1.0
Vertex Shader >= 1.0Vertex Shader >= 1.0
DX >= 9DX >= 9
Video RAM >=120 MBVideo RAM >=120 MB
Pixel Shader >= 2.0Pixel Shader >= 2.0
Vertex Shader >= 2.0Vertex Shader >= 2.0
Multitexture units >=4Multitexture units >=4
Tier 0
Everything is unaccelerated
Tier 1 (YES)
Most 2-D Rendering & 3-D
Rasterization
Tier 1 (NO)
3D lighting calculations, Color-keyed
alpha and Text rendering
Tier 2 (YES)
Radial Gradients
3-D lighting calculations
Text rendering
3-D antialiasing (Windows Vista™ only)
Always unaccelerated
Bitmap Effects, Printed Content,
RenderTargetBitmap
Tilebrush (Tilemode == Tile), Big
Surfaces
Operations requires more RAM, then
available in video card
Layered windows
0%
20%
40%
60%
80%
100%
Before
After
99%
1% 0%
Rendering Application
System
61%
4%
35%
Rendering Application
System
Before After
Don’t put performance testing to the end
Do prioritize performance in dev. Plan
“Kill ‘em when they small”
Plan performance-oriented features
Test on real world hardware
Share your knowledge with designers
Know how things work “under the hoods”
Just code – Tamir Khason
http://blogs.microsoft.co.il/blogs/tamir/
WPF Performance on MSDN
http://msdn2.microsoft.com/en-us/library/aa970776.aspx
Josh Smith on WPF
http://joshsmithonwpf.wordpress.com/
Henry Hahn – WPF Program Manager
http://blogs.msdn.com/henryh/
Tim Cahill – WPF Performance Guidance
http://blogs.msdn.com/timothyc/
Windows Presentation Foundation SDK
http://blogs.msdn.com/wpfsdk/
Ian Who – VSTS profiler
http://blogs.msdn.com/ianhu/
Rico Mariani – Performance Tidbits
http://blogs.msdn.com/ricom/
Dwayne Need – Presentation Source
http://blogs.msdn.com/dwayneneed/
?‫הייתי‬ ‫איך‬
!‫לדעת‬ ‫מאוד‬ ‫לי‬ ‫חשוב‬
‫הקדישו‬ ‫בבקשה‬2
‫את‬ ‫ומלאו‬ ‫דקות‬
‫המשוב‬
© 2007 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.
t-shirts*

More Related Content

Similar to WPF for developers - optimizing your WPF application

Build 2017 - B8100 - What's new and coming for Windows UI: XAML and composition
Build 2017 - B8100 - What's new and coming for Windows UI: XAML and compositionBuild 2017 - B8100 - What's new and coming for Windows UI: XAML and composition
Build 2017 - B8100 - What's new and coming for Windows UI: XAML and compositionWindows Developer
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2iedotnetug
 
MySQL Monitoring Shoot Out
MySQL Monitoring Shoot OutMySQL Monitoring Shoot Out
MySQL Monitoring Shoot OutKris Buytaert
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Doris Chen
 
Optimizing Flex Applications
Optimizing Flex ApplicationsOptimizing Flex Applications
Optimizing Flex Applicationsdcoletta
 
Java Enterprise Performance - Unburdended Applications
Java Enterprise Performance - Unburdended ApplicationsJava Enterprise Performance - Unburdended Applications
Java Enterprise Performance - Unburdended ApplicationsLucas Jellema
 
ILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterpriseILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterpriseRené Winkelmeyer
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web ComponentsRed Pill Now
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...goodfriday
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NETPeter Gfader
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
 
Advanced Silverlight
Advanced SilverlightAdvanced Silverlight
Advanced Silverlightrsnarayanan
 
Moving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, trapsMoving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, trapsFlorian Weil
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinBarry Gervin
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebJames Rakich
 
From Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceFrom Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceSebastian Springer
 

Similar to WPF for developers - optimizing your WPF application (20)

Build 2017 - B8100 - What's new and coming for Windows UI: XAML and composition
Build 2017 - B8100 - What's new and coming for Windows UI: XAML and compositionBuild 2017 - B8100 - What's new and coming for Windows UI: XAML and composition
Build 2017 - B8100 - What's new and coming for Windows UI: XAML and composition
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2
 
MySQL Monitoring Shoot Out
MySQL Monitoring Shoot OutMySQL Monitoring Shoot Out
MySQL Monitoring Shoot Out
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016
 
Optimizing Flex Applications
Optimizing Flex ApplicationsOptimizing Flex Applications
Optimizing Flex Applications
 
Java Enterprise Performance - Unburdended Applications
Java Enterprise Performance - Unburdended ApplicationsJava Enterprise Performance - Unburdended Applications
Java Enterprise Performance - Unburdended Applications
 
ILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterpriseILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterprise
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web Components
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NET
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Visual State Manager
Visual State ManagerVisual State Manager
Visual State Manager
 
Advanced Silverlight
Advanced SilverlightAdvanced Silverlight
Advanced Silverlight
 
Moving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, trapsMoving from AS3 to Flex - advantages, hazards, traps
Moving from AS3 to Flex - advantages, hazards, traps
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
Droidcon Paris 2015
Droidcon Paris 2015Droidcon Paris 2015
Droidcon Paris 2015
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the Web
 
From Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceFrom Zero to Hero – Web Performance
From Zero to Hero – Web Performance
 
Flex 4 tips
Flex 4 tipsFlex 4 tips
Flex 4 tips
 

More from Tamir Khason

Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client DevelopmentTamir Khason
 
Understanding Reflection
Understanding ReflectionUnderstanding Reflection
Understanding ReflectionTamir Khason
 
Creating A Game Using Microsoft’s Next Generation Technologies
Creating A Game Using Microsoft’s Next Generation TechnologiesCreating A Game Using Microsoft’s Next Generation Technologies
Creating A Game Using Microsoft’s Next Generation TechnologiesTamir Khason
 
Modern C&C Systems, Using New Technologies
Modern C&C Systems, Using New TechnologiesModern C&C Systems, Using New Technologies
Modern C&C Systems, Using New TechnologiesTamir Khason
 
Wpf Under The Hood Engines
Wpf Under The Hood EnginesWpf Under The Hood Engines
Wpf Under The Hood EnginesTamir Khason
 
Introduction To Wpf Engines
Introduction To Wpf   EnginesIntroduction To Wpf   Engines
Introduction To Wpf EnginesTamir Khason
 

More from Tamir Khason (6)

Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client Development
 
Understanding Reflection
Understanding ReflectionUnderstanding Reflection
Understanding Reflection
 
Creating A Game Using Microsoft’s Next Generation Technologies
Creating A Game Using Microsoft’s Next Generation TechnologiesCreating A Game Using Microsoft’s Next Generation Technologies
Creating A Game Using Microsoft’s Next Generation Technologies
 
Modern C&C Systems, Using New Technologies
Modern C&C Systems, Using New TechnologiesModern C&C Systems, Using New Technologies
Modern C&C Systems, Using New Technologies
 
Wpf Under The Hood Engines
Wpf Under The Hood EnginesWpf Under The Hood Engines
Wpf Under The Hood Engines
 
Introduction To Wpf Engines
Introduction To Wpf   EnginesIntroduction To Wpf   Engines
Introduction To Wpf Engines
 

Recently uploaded

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

WPF for developers - optimizing your WPF application

  • 1.
  • 2. Tamir Khason Software consulter mPrest systems : . . .http //blogs microsoft co il/blogs/tamir
  • 3.
  • 4. Think in terms of scenario Don’t push to the limit Do only what you have to do Set your final goals Target customer’s expectations Don’t try to do things “smarter”
  • 5. WPF is managed code Don’t forget about memory Do as little as possible on startup WPF is retained system You have no pixels, you have a tree Minimize trees, keep changes locally
  • 6. DependencyDependency ObjectObject VisualVisual UIElementUIElement Framework ElementFramework Element ControlControl ShapeShape FreezableFreezable AnimatableAnimatable DrawingDrawingGeometryGeometry Style, Resources, Binding, PropertiesStyle, Resources, Binding, Properties TemplatesTemplates AnimationAnimation Transformation, Bounds, ClipTransformation, Bounds, Clip Input, Focus, Layout, Routed EventsInput, Focus, Layout, Routed Events Change notifications, multithreadingChange notifications, multithreading
  • 7.
  • 8.
  • 9.
  • 10. Rendering threadRendering thread – mostly GPU, unmanaged Part of tree to render, PROBLEMS (which hard to detect) UI threadUI thread - CPU only, managed All services, your code, tree, PROBLEMS
  • 11. Bitmap Effects RenderTargetBitmap Tilebrush Operations requires more RAM, then available in video card Layered windows
  • 12.
  • 13. Your code is running here It runs in CPU only Visual tree is living here Most of your performance problems are here!
  • 14. Use smaller Visual Tree Don’t force unnecessary measurements Virtualize your data Use static resources Move your code into other thread Create your own other UI threads
  • 15. FrameworkElement is not base class Shapes vs. Drawing Polyline vs. StreamGeometry Not every “control” is control Each TextBox contains 30 elements Each Label contains 5 elements Each TextBlock contains only one
  • 16. Use TextBlock Use TextFormatter Or even GlyphRuns directly TextBlock is 32 times faster then FlowDocument Use fewer elements, everything in WPF have costs
  • 17. Label = 3 X 5 = 15Label = 3 X 5 = 15 Grid = LayoutGrid = Layout ViewBox = Layout +ViewBox = Layout + MeasurementsMeasurements ListBox is too complicated forListBox is too complicated for such layoutsuch layout VirtualizingStackPanel is 70xVirtualizingStackPanel is 70x faster, then StackPanelfaster, then StackPanel
  • 18. ScrollViewer ScrollBarVisibility = Auto Don’t calculate nothing Don’t tickle Layout Engine FrameworkElement Width/Height= Auto Don’t you know the real size of content? Resize = layout = tree walk Why to measure? GridLength.Star, ResizeMode, SizeToContent Want dynamic behavior – do it, but not too much Make sure, it’s absolutely necessary Canvas in the smallest content control – it much smaller, then Grid More rows and columns means bigger tree Custom cell template = more then 60 FrameworkElements
  • 19. Instantiate on demand VirtualizingStackPanel is 70x faster, then StackPanel You can virtualize data by yourself Virtualization does delete and create tree – measure before implementing
  • 20. StaticResource vs. DynamicResource StaticResource = one evaluation DynamicResource = one reference Use ResourceDictionary to share resources You can Load and Unload resources on demand Scale your images Freeze whenever you can
  • 21. IList vs. IEnumerable XML vs. CLR SelectedIndex calls to IndexOf Set DataContext instead XAML and switch it on Application.OnActivated
  • 22. DependencyProperty is x3 faster, then INotifyPropertyChanged ICustomPropertyDescriptor is your friend for vary property set ObservableCollection<T> is x90 faster accesses single item, then List<T> ObjectDataProvider is x20 smaller, then XmlDataProvider
  • 23. <ObjectDataProvider x:Key="cars" ObjectType="{x:Type l:Cars}" IsAsynchronous="True“/> … <Canvas DataContext="{StaticResource cars}“> <Image Width="1024" Height="768" Source="{Binding Path=BigImage, Mode=OneWay, NotifyOnTargetUpdated=True}" RenderOptions.CachingHint="Cache" RenderOptions.BitmapScalingMode="LowQuality"> </Canvas> It’s asynchronousIt’s asynchronous It applies everywhere onlyIt applies everywhere only onceonce It’s manual and one wayIt’s manual and one way And saves a lotAnd saves a lot of unmanagedof unmanaged resourcesresources
  • 24. public class Car : DependencyObject public static readonly DependencyProperty BigImageProperty; FrameworkPropertyMetadata( default(BitmapSource), FrameworkPropertyMetadataOptions.None)); public class Cars : ObservableCollection<Car> Setter is slower, but getter isSetter is slower, but getter is much fastermuch faster This property does notThis property does not affects neitheraffects neither measurement, normeasurement, nor renderingrendering It’s much better to add andIt’s much better to add and remove items withoutremove items without regeneration controlregeneration control
  • 25. DispatcherOperation oper = Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, LoadFromXML); Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, (SendOrPostCallback)delegate(object o) { CreateCarNode (o); }, node) BitmapImage image; image. DecodePixelWidth = 200; image.Freeze(); Invoke time consumingInvoke time consuming operations asynchronouslyoperations asynchronously with low prioritywith low priority Invoke recent and fast operationsInvoke recent and fast operations asynchronously with low priorityasynchronously with low priority Scale and freeze unmanaged and staticScale and freeze unmanaged and static resourcesresources
  • 26. ColdStart - After reboot or long period of time Resources are not presents System calls (registry, disk) WormStart CLR components are already loaded Resources are allocated
  • 27.
  • 28. Tier 0Tier 0 Tier 1Tier 1 Tier 2Tier 2 DX < 7DX < 7 7 <= DX < 97 <= DX < 9 Video RAM >= 30MBVideo RAM >= 30MB Pixel Shader >= 1.0Pixel Shader >= 1.0 Vertex Shader >= 1.0Vertex Shader >= 1.0 DX >= 9DX >= 9 Video RAM >=120 MBVideo RAM >=120 MB Pixel Shader >= 2.0Pixel Shader >= 2.0 Vertex Shader >= 2.0Vertex Shader >= 2.0 Multitexture units >=4Multitexture units >=4
  • 29. Tier 0 Everything is unaccelerated Tier 1 (YES) Most 2-D Rendering & 3-D Rasterization
  • 30. Tier 1 (NO) 3D lighting calculations, Color-keyed alpha and Text rendering Tier 2 (YES) Radial Gradients 3-D lighting calculations Text rendering 3-D antialiasing (Windows Vista™ only)
  • 31. Always unaccelerated Bitmap Effects, Printed Content, RenderTargetBitmap Tilebrush (Tilemode == Tile), Big Surfaces Operations requires more RAM, then available in video card Layered windows
  • 32.
  • 35. Don’t put performance testing to the end Do prioritize performance in dev. Plan “Kill ‘em when they small” Plan performance-oriented features Test on real world hardware Share your knowledge with designers Know how things work “under the hoods”
  • 36.
  • 37. Just code – Tamir Khason http://blogs.microsoft.co.il/blogs/tamir/ WPF Performance on MSDN http://msdn2.microsoft.com/en-us/library/aa970776.aspx Josh Smith on WPF http://joshsmithonwpf.wordpress.com/ Henry Hahn – WPF Program Manager http://blogs.msdn.com/henryh/ Tim Cahill – WPF Performance Guidance http://blogs.msdn.com/timothyc/ Windows Presentation Foundation SDK http://blogs.msdn.com/wpfsdk/ Ian Who – VSTS profiler http://blogs.msdn.com/ianhu/ Rico Mariani – Performance Tidbits http://blogs.msdn.com/ricom/ Dwayne Need – Presentation Source http://blogs.msdn.com/dwayneneed/
  • 38. ?‫הייתי‬ ‫איך‬ !‫לדעת‬ ‫מאוד‬ ‫לי‬ ‫חשוב‬ ‫הקדישו‬ ‫בבקשה‬2 ‫את‬ ‫ומלאו‬ ‫דקות‬ ‫המשוב‬
  • 39.
  • 40. © 2007 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. t-shirts*

Editor's Notes

  1. Move to end
  2. Move to end
  3. Move to end
  4. move to end
  5. Please customize this slide with the resources relevant to your session
  6. Please customize this slide with the resources relevant to your session