Upload
engineering-software-lab
View
2.910
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Contents
• Application Resources• Layouts & Templates• Data Binding• Converter vs. DataTemplateSelector• XamDataGrid-specific optimizations
– UI Virtualization– Themes and styles– Real-time updates
• Initial Loading Time (preloading and NGEN)
Application Resources
• Load relevant resources at the view level (as opposed to on the application level)
• Use shared resource definitions on the Window/Application level
• Use static resources rather than dynamic ones to save on lookups at runtime
Layouts & Templates
• Reduce the number of visual elements• Use virtualized container with recycling• Refrain from using BitmapEffects• Set the neutral culture using
NeutralResourcesLanguageAttribute to prevent lookup of satellite assemblies
Data Binding
• Fix binding errors to prevent expensive binding path resolutions
• Binding to many properties of an object is expensive compared to binding to few properties of many objects
• Test with 1000 textboxes– Bound to 1 object’s 1000 properties – 950ms– Bound to 1000 objects 1 property – 115ms
Data Binding
• Bind to IList rather than IEnumerable, because the CLR generates an IList to wrap it
• For adding/removing data from data sources, bind to ObservableCollection<T> rather than IList
Convertor vs DataTemplateSelector
• Use Convertors instead of DataTemplateSelectors– Added flexibility in specifying business logic– Slightly better performance
• For virtualized control, the convertors will be invoked for each cell coming into view,
• Apply processing in code-behind and bind to transformed/formatted data
Convertor Limitations
• For virtualized item controls, the conversion logic will be invoked for each cell coming into view
• Avoid unbound columns and convertors - apply processing in code-behind and bind to transformed data
• Apply formatting using styles rather than converters, e.g. date or time formatting
XamDataGrid UI Virtualization
• XamDataGrid supports virtualization modes on the row and column level to help you adjust performance for your specific scenarios
• You can customize the virtualization setting using the RecordContainerGenerationMode and CellContainerGenerationMode properties
XamDataGrid Virtualization Modes
• Recycle– Reuses the same visual elements, binding
them to data items as they are scrolled into view
– Minimize space requirement at the expense of time
– Suitable for high-volume data scenarios with simple UI controls in the cells
XamDataGrid Virtualization Modes
• PreLoad– Initialize visual elements to represent the
entire dataset– Improve runtime performance at the expense
of space and startup time– Useful when you require smooth scrolling
over a relatively small dataset, and you have user controls hosted in the control with expensive initialization/formatting applied
XamDataGrid Virtualization Modes
• LazyLoad– Initialize visual elements to represent the visible
dataset, adding new ones to represent data subsequently brought into view
– Minimum space at startup, increasing space footprint, accessing cells that have been in view is fast
– Useful when you require smooth scrolling over a relatively small dataset, and you have user controls hosted in the control with expensive initialization/formatting applied
XamDataGrid Event Suppress
• Suppress unused routed events to improves performance due to the overhead incurred with routed events in element hierarchies.
• There are also direct CLR events added for common routed events on the DataPresenterBase.
XamDataGrid Themes & Styles
• Set the Theme property to prevent overhead in template lookup– Implications for preloading
• Use a hover-less theme to prevent row highlighting on mouse hover
XamDataGrid Real-Time Updates
• Using INotifyPropertyChanged on the property level (usual MVVM setup)– Useful for sparse updates, good for most cases– One event updates one bound column
• Using INotifyPropertyChanged on the row level– Useful for scenarios where all the properties in a
row are changed. This updates the entire row using a single property changed notification, instead of raising N property changed events
– One event updates an entire row
XamDataGrid Real-Time Updates
• Using CollectionChanged.Reset for frequent and extensive data updates– Useful for scenarios where the underlying
datasource changes dramatically – e.g. a new batch of rows come in from a backend system
– One event updates the entire grid
XamDataGrid ReadOnly Style
• Using the read-only cell style (provided on my blog), you can get a radically simpler CellValuePresenter style, which improves performance
• It does not render editors for cells in edit mode,
• Setting EditAsType the same type for all XamDataGrid fields facilitates cell virtualization
Initial Loading Time - Preloading
• Preloading XamDataGrid (and any other Infragistics controls) in a window not shown to the user pays upfront the cost of JIT-compiling the XamDataGrid
• This causes user-initiated opening of a window containing the XamDataGrid to be much faster
• Approach is described here
Initial Loading Time - NGEN
• The JIT compiler compiles methods as required during execution– Takes up CPU time– Compiled code cannot be shared among
processes
Initial Loading Time - NGEN
• Using NGEN to create pre-compiled (native) images of Infragistics DLLs to eliminate JIT-compilation– Reduces the memory footprint
• JIT compiler does not need to be loaded in memory)• Native images can be shared among processes
– Improves loading time in warm startup scenarios
Note: NGEN’ed assemblies need to be in the GAC on the client machine in order to avoid costly strong-name validation procedure.
Questions
Resources
Optimizing XamDataGrid performancehttp://blogs.infragistics.com/blogs/kiril_matev/archive/2010/10/26/optimizing-xamdatagrid-performance.aspx
Optimizing WPF Application Performancehttp://msdn.microsoft.com/en-us/library/aa970683.aspx