WPF Performance and .NET Framework Client Profile

WPF performance and .NET Framework Client Profile related blogs provided by Jossef Goldberg.

June, 2010

  • WPF Performance and .NET Framework Client Profile

    Software Rendering Usage in WPF

    • 8 Comments

    As you know by default WPF uses Hardware acceleration (GPU) to render its content (aka Hardware rendering).
    In most cases rendering using Hardware (HW) acceleration is much more performant than rendering using Software. In some small cases SW rendering may be faster (E.g. low end graphics card sometimes found in Netbooks).

    WPF will always attempt to use HW rendering, but in certain cases WPF will fall to Software rendering and the application may not be aware of it.
    Some folks wanted to better understand all the possible cases, so am I am listed these below.
    WPF will render in Software when:

    1. Machine video driver date is old (before 11/2004)
    2. WPF detected a "Tier 0" graphic card.
      This means that no graphics hardware acceleration is supported and DirectX version level is less than version 7.0.
    3. The rendered Window's size exceeds the max video card texture size.
      One common scenario for this to happen if you have a WPF window spanning across multiple monitors.
    4. You run your application over Remote Desktop Protocol (e.g. Remote Desktop, Terminal Server, Remote Assistant, etc)
      Until NET 3.5 SP1 and earlier, remoting between Vista to Vista with DWM on, leveraged a custom WPF primitive remoting protocol. In all other scenarios content was remoted as bitmaps. Starting with the release of NET 3.5 SP1 (including NET 4), WPF renders the application content using a software rasterizer on the server and then remotes the content as bitmaps in all cases. Read more here.
    5. Rendering in Virtual Machine.
      WPF will try and render in HW but on some VMs the graphic emulator that comes with the VM is not working correctly. User will have to switch to software to fix the problem. 
    6. The Application is calling the force Software API. E.g.
      RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;       // Force Software rendering per Process – New in NET4
      hwndTarget.RenderMode = RenderMode.SoftwareOnly;        // Force Software rendering per Window– Introduced in Net 3.5 SP1
    7. You set the global registry key. E.g.:
      (HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics] 
      "DisableHWAcceleration"=dword:00000000 )
      Note: Since this reg key impacts all WPF application consider using this key for testing purposes only.
    8. Application uses legacy style bitmap effects.
      Note: these are obsolete in NET4.
    9. Application printed content.
    10. Rasterized content that uses RenderTargetBitmap
    11. Tiled content that uses TileBrush
    12. Use of too many light objects in your 3D scene. Read more here.
    13. Layered windows (only on XP SP2/W2k3 or before that do not have Hotfix installed.
      See: http://support.microsoft.com/kb/937106/en-us.
    14. Graphics hardware failures, such as "Out Of Video Memory" (OOVM).
      WPF try to free up video memory and stay in HW rendering but it may not always work and WPF will fall to Software  


    Which tools can I use to detect if my app renders in Software?
    The easiest way is to use Perforator which is included with the WPF Performance Profiling Tools and check below check boxes.
    Read more here.

    Option

    Description

    Draw software rendering with purple tint

    Draws all areas rendered by using the software rendering pipeline with a purple tint. This includes software render targets, software 3D content, and per-primitive software fallback.

    Draw software rendered bitmap effects with red tint

    Draws legacy software rendered bitmap effects with red tint.


    How can I detect if my app renders in Software in code?

    Check the RenderingCapability.Tier . You can also listen on the Tier change event.

  • WPF Performance and .NET Framework Client Profile

    Memory Leak Hotfixes for WPF 3.5 SP1

    • 3 Comments

    Hopefully folks saw my related blog post Finding Memory Leaks in WPF-based applications .
    In this post below I wanted folks to be aware that we released few other KB Articles (Hotfix) that address other various memory leaks reported in .NET 3.5 SP1. Some of these fixes made it to .NET 4.

    1. KB981107 (See: http://support.microsoft.com/kb/981107)

    This Hotfix fixes the following memory leaks in .NET 3.5 SP1 WPF-based applications.
    Issue 1:
    This affects an app that contains styles or templates that refer to application resources (via StaticResource or DynamicResource), and that creates a large number of elements that use these styles or templates but never need the actual value of the resource.  In this situation, the app can leak DeferredAppResourceReference objects, even after the elements themselves have been reclaimed.  (In addition, the app can leak WeakReferences and array space, similar to the issues described below.)

    An example:  App resources define   <sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">20</sys:Double>     This creates a resource that's used by any control that can display a horizontal scrollbar.  Creating a large number of such controls that never actually display their scrollbar will encounter the leak.

    Issue 2:
    This affects an app that creates a large number of short-lived elements with properties that are data-bound to a DependencyProperty of longer-lived elements. In this situation, the longer-lived elements maintain lists of WeakReference objects, used to notify the short-lived elements about property changes. The app can leak WeakReference objects and the array space to hold them, even after the short-lived elements have been reclaimed.

    An example:   ListBoxItem binds its HorizontalContentAlignment property to a similar property on its governing ListBox.   An app that creates a large number of ListBoxItems (say by doing a large number of additions and deletions to the ListBox's ItemsSource) will encounter the leak.

    Issue 3:
    This issue affects classes derived from TreeView or Selector (including ListBox, ListView, Menu, DataGrid, and many others).   These classes register for an internal notification from the KeyboardNavigation class, used for controlling keyboard focus.   An app that creates a large number of these elements can leak WeakReference objects and the array space to hold them, even after the elements themselves have been reclaimed.
    An example:  An app that creates a large number of short-lived ListBoxes will encounter the leak.  This can happen in a nested scenario, where an outer ListBox displays a collection that undergoes a large number of additions and deletions, and where each item is displayed using an inner ListBox.

    These fixes are not included in NET4. We are considering this Hotfix also for NET4, but this decision has not been made, so stay tune.

    2. KB967634: (See: http://support.microsoft.com/kb/967634 )

    This fixes a memory leaks in .NET 3.5 SP1 WPF-based applications when using software 3D rendering involving a VisualBrush or DrawingBrush.
    This fix is already included in .NET 4.

    3. KB967328 (See: http://support.microsoft.com/Default.aspx?kbid=967328)

    This Hotfix fixes memory leaks when a deferred resource isn't inflated due to the resource reference expression hooking up to the Inflated event on the resource dictionary entry.
    If the resource dictionary is an application or theme dictionary, then these are essentially global and can cause these expressions to stay alive.
    There are some discussions on this issue here.
    This fix is already included in .NET 4.

  • WPF Performance and .NET Framework Client Profile

    WPF “Airspace” when using WEB Browser control

    • 0 Comments

    As you may know, when you interoperate WPF with other technologies you can't overlay WPF and WinForms/Win32 content because of the "airspace" limitations (read more here).
    Any given pixel in a window is either owned by WPF or WinForms/Win32, not both. On the other hand, you can overlay all the WPF content you want because WPF manages and renders all of them.

    Many folks however are looking to overlay WPF content over Web content. Chris Cavanagh posted sometimes ago a blog that explain how you can do so using Google's web control.
    Sources for a sample are available on Codeplex. You would need to license the wrapper called Awesomium.

Page 1 of 1 (3 items)