user2604650
user2604650

Reputation:

Does containers nesting in XAML affect rendering performance?

Does the rendering performance reduce seriously in case when WPF application's XAML contains a lot of nested Grid, StackPanel, DockPanel and other containers?

Upvotes: 1

Views: 797

Answers (3)

Vimal CK
Vimal CK

Reputation: 3563

WPF uses MeasureOverride and ArrangeOverride methods inorder to render UIElements. MeasureOverride measure the UIElements width and size based on the Parent controls Width and Size. ArrangeOVerride method will arrange the UIElements at runtime based on these measures. These methods are optimized for faster performance and should not cause any rendering performance issue.

But there should be a capacity where these methods can handle UIElements within a minimal time. If this limit exceeds then there should be performance issue.

eg: Suppose a bike can carry 2 person. if 5 persons overloaded what will happen :)

Jet Brains .Trace is a tool to analyze the performance issue which will helps to see these two methods

Upvotes: 0

Gusdor
Gusdor

Reputation: 14334

Really the answer is simply "yes". More of anything will use more processor time. SURPRISE!

In the case of WPF, elements are arranged into a hierarchical scene graph. Adding levels of depth to this graph will slow your application more than adding siblings to existing elements. You should always strive to keep the depth the graph low. Consider using Grid instead of nesting StackPanels.

So why is depth more important than raw element count? Well, depth generally implies;

  1. layout dependency - if a parent is re-sized a child is likely to be re-rendered.
  2. occlusion - if 2 elements overlap, invalidating one will often invalidate the other.
  3. recursion - most graph operations are CPU bound - they depend entirely on CPU speed and have no dedicated hardware support (the renderer uses your graphics chip where possible). Cycling through levels of the graph for resources and layout updates is expensive.

Concerning occlusion, the BitmapCache class can help greatly!

Upvotes: 3

Fernando Urkijo
Fernando Urkijo

Reputation: 3515

When you create a very complex UI, with lots of nested objects and DataTemplate with lot of elements, you can impact seriously the performance of the App, because the bigger the UI Tree, the bigger it will take to render, and if the framework cannot render in 30FPS you will start to see performance drops. You should use the most lightweight panels you need in order to avoid extra logic you wonn't need. Here are some performance tips in order to make you App faster:

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

Upvotes: 2

Related Questions