Quantcast
Channel: Developer Express Inc.
Viewing all articles
Browse latest Browse all 2389

Increase WPF App Performance with Lightweight DevExpress Themes

$
0
0
What if your next DevExpress-powered (classic theme based) WPF application loaded nearly twice as fast? And what if I told you that you could achieve this very thing with a simple theme change?
By switching from classic DevExpress themes to lightweight DevExpress WPF themes, you can improve startup speed, reduce memory consumption, and enhance overall responsiveness. In this post, I’ll outline the benefits of lightweight themes and key factors to consider when updating your app. With that brief teaser, let's dig into the details and show you how to incorporate lightweight WPF themes in your project...

Application Startup

As you may know, we introduced lightweight themes in our v23.2 release cycle. When compared to classic themes in v23.1, lightweight themes offer the following startup performance improvements:

Note: Actual performance gains will vary based on .NET version, whether Ngen or ReadyToRun is used, and other app-specific factors. We’ve uploaded additional benchmark data in the following GitHub repository: WPF Lightweight Themes - Performance Tests.
To achieve these improvements, we overhauled our WPF theme implementation and included the following optimizations:
  • Restructured resource dictionaries to reduce search depth.
  • Removed unnecessary parts of the default DeepBlue theme.
  • Reorganized theme keys to use fewer classes and reduce JIT compilation.
  • Enhanced caching for images loaded from the DevExpress.Images library.
These enhancements reduce the time associated with JIT initialization, XAML parsing, and resource loading (to reduce startup time even further, consider enabling Multi-Core JIT and ReadyToRun in your app. I discussed these techniques in the following blog post: 9 Tips to Reduce WPF App Startup Time).

View Switching

In addition to startup time, lightweight theme optimizations helped improve view switching performance. As you'd expect, users can now interact with our UI controls more quickly when they open a view for the second time.

With this change, you can expect faster tab switching, navigation, panel docking/undocking, and enhanced app responsiveness.

Memory Usage

Because we now use fewer XAML resources, lightweight themes consume less memory (both RAM and local disk usage).

Effective memory management helps reduce performance issues and reduce power consumption on devices such as laptops. This fact is especially important on older devices, where the OS can create swap files on the local disk when RAM is insufficient.
Since all lightweight themes share multiple XAML resources, we combined them into a single assembly that only requires 11 MB of space (compared to 10 assemblies totaling 72 MB in a similar set of classic themes).

Simplified Access to Palette Colors

In addition to performance and memory enhancements, lightweight themes simplify palette color usage. To reference a theme color in your app, simply specify the color name in the ThemeResource extension:
<Border BorderBrush="{dxci:ThemeResource ThemeKey='Brush.Border'}"/>
You can also specify different colors based on the currently applied theme:
<Border BorderBrush="{dxci:ThemeResource ThemeKey='Brush.Border, 
                     Win11Light=Brush.Custom.Red'}" />
By referencing default colors, you can synch the appearance of DevExpress/other UI elements in your app.

Upgrade Path to Lightweight Themes

To activate lightweight themes, add the DevExpress.Wpf.ThemesLW package and invoke the following code during application startup:
CompatibilitySettings.UseLightweightThemes = true;
ApplicationThemeHelper.ApplicationThemeName = LightweightTheme.Win11Light.Name;
If you’ve customized classic themes, note the following:
  • Lightweight themes do not support the DevExpress WPF Theme Designer. If you mainly used the Theme Designer for color customization, you can override colors using custom palettes. This technique allows you to specify most theme colors without building a new assembly. For more complex customizations, you can use built-in control APIs or modify theme resources.
  • Lightweight theme resources have different key names compared to classic themes. If you’ve overridden classic resources in your app, most of them should work for lightweight themes, but minor modifications may be necessary. For example, the ThemeName attribute won’t work with old theme keys. We’ve described these differences in the following help topic: Modify Lightweight Theme Resources.
Switching to lightweight themes should be straightforward. However, even if you choose to stay with classic themes, consider upgrading to v23.2 or newer, as this version improves performance in classic themes as well. You can expect up to a 30% startup performance improvement compared to v23.1.

Future Updates

We will continue working on performance enhancements in future release cycles (we expect to optimize font loading performance within the WPF Rich Text and Font Editors in our v25.1 release cycle). Additionally, we've reduced view load time and memory consumption in our demos to help you better evaluate performance improvements across our controls. If you encounter any challenges when using lightweight WPF themes, feel free to create a DevExpress Support Center ticket - we'll be happy to follow up.
And one more reminder - don't forget to check out my other WPF performance-related blog post: 9 Tips to Reduce WPF App Startup Time.

Viewing all articles
Browse latest Browse all 2389

Trending Articles