Troubleshoot Performance
- 7 minutes to read
Identify performance bottlenecks and optimize application startup, control initialization/rendering, and data access.
Speed Up Application Startup
When you build a .NET application, it is compiled to Microsoft Intermediate Language (MSIL). At runtime, the Just-In-Time (JIT) compiler translates MSIL into native machine code. This process may introduce startup delays.
Use Ahead-of-time (AOT) compilation to partially compile MSIL into native code at publish time. This technique reduces the need for JIT compilation and improves startup performance.
For example, you can publish your application in ReadyToRun (R2R) format to speed up startup. The application file size may increase because executables contain both native and MSIL code.
Activate the <PublishReadyToRun>
option in the .csproj file:
<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
Refer to the following help topic for more information: Reduce Application Launch Time.
Reduce Loading Time of a Form/Control/Module
At startup, the .NET runtime creates the form, initializes UI controls, applies layout logic, sets up event handlers, and applies skins. Each of these steps contributes to the overall startup time.
The more complex the UI, the longer these operations take. Multiple UI controls and nested hierarchies can slow down form initialization and rendering.
To improve startup performance, minimize the number of controls per form or user control and simplify layouts wherever possible.
Tip
You can delay form display until all controls are fully initialized. Override the main form’s XtraForm.ShowMode
property to return FormShowMode.AfterInitialization
:
The following techniques reduce initialization time and preserve a rich user interface:
Modular App Structure
Use logical modules with fewer controls, each implemented as an XtraUserControl. Display one module at a time.
Navigation Containers
Use navigation containers to host groups of controls that do not need to be visible immediately. Controls within inactive tabs or frames are not fully initialized until the user activates the tab or frame.
Supported containers include:
- XtraTabControl
- Navigation Frame
- Tab Pane
- TabbedGroup (in LayoutControl)
- Tabbed View
Deferred Load
If a view contains a DocumentManager with multiple documents, use Deferred Load. In this mode, inactive documents do not load their content when the application starts.
Speed up a Form/Control/Module
Rework Event Handlers
A performance drop may relate to events that customize individual elements within a control:
- Events that change element appearance (GridView.CustomDrawCell)
- Events that supply/modify element values (GridView.CustomUnboundColumnData)
Review and optimize code in such event handlers.
Find Time-consuming Code
- Check for complex logic in frequently raised events.
- Use a performance profiler tool (for example, the built-in VS profiler or dotTrace) to find bottlenecks.
- Comment out code line by line to find time-consuming operations.
Optimize Slow Code
- Move complex code from frequently executed event handlers.
- Use caching or background threads.
Profile Data Access Operations
Data access operations may affect performance due to query execution time, network latency, data volume, concurrent transactions, etc.
To find bottlenecks, use a database performance profiling tool (for example, SQL Server Profiler).
For more information, refer to the following help topic: Performance Optimization.
Check for Unhandled Exceptions
The Windows Forms platform or DevExpress controls may silently catch exceptions. A rapid performance drop may indicate a repeated unhandled exception.
Enable exception handling and identify/fix exceptions (if any). Refer to the following help topic for more information: Application Crashes or Throws an Exception.
Speed Up an Application on a Remote Client
When a WinForms application runs on a remote client (for example, Remote Desktop), the application constantly takes snapshots of its windows to render the UI on the client side. Visual effects, animations, or complex UIs can increase CPU and network load, which impacts performance.
To optimize performance in remote sessions, set the WindowsFormsSettings.OptimizeRemoteConnectionPerformance property to DefaultBoolean.True
at application startup:
using DevExpress.XtraEditors;
using DevExpress.Utils;
namespace test {
internal static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
WindowsFormsSettings.OptimizeRemoteConnectionPerformance = DefaultBoolean.True;
Application.Run(new MainView());
}
}
}
Eliminate Flickering
Flickering occurs when a form executes long-running operations during initialization. In WinForms, a form calculates the layout, binds events, and instantiates and renders controls.
If these stages take a noticeable amount of time, the form may appear partially rendered and exhibit visual flicker.
To eliminate flickering, use an XtraForm (or its descendant) and display the form only after it is fully initialized. Override the XtraForm.ShowMode
property to delay form display until all initialization steps are complete:
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
}
protected override FormShowMode ShowMode {
get {
return FormShowMode.AfterInitialization;
}
}
}
Eliminate Repeated Image Conversions
When image data is stored as byte arrays, a data-aware control (for example, Data Grid, Tree List, Gantt Control, or Vertical Grid) converts each byte array to a raster or SVG image every time a cell is painted. Repeated conversions during scrolling or refresh operations can significantly reduce performance.
To optimize rendering, work with Image
objects (do not store image data as byte arrays in your bound records). For example, create a Data Transfer Object (DTO) that stores an Image
instance, and convert the byte array to an image only once on object initialization:
public class Employee {
public Employee(byte[] photoBytes) {
using(var ms = new MemoryStream(photoBytes))
Photo = Image.FromStream(ms);
}
public Image Photo { get; }
}
Tip
To detect resource-consuming conversion and other rendering-related issues, call the WindowsFormsSettings.ForcePaintApiDiagnostics method at application startup. A ByteArrayToImageConversionWarning
exception is thrown for each repeated image conversion.
using DevExpress.XtraEditors;
using DevExpress.Utils.Diagnostics;
namespace test {
internal static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
WindowsFormsSettings.ForcePaintApiDiagnostics(PaintApiDiagnosticsLevel.Throw);
Application.Run(new Form1());
}
}
}
Speed up the Visual Studio Designer
The Visual Studio Designer can experience performance degradation or freezes due to design-time exceptions, installed Visual Studio extensions, or the open Document Outline window.
To speed up the Visual Studio Designer, do the following:
- Deactivate all Visual Studio extensions
- Eliminate extension-related issues.
- Close the Document Outline window
- Reduce layout recalculations and UI updates during design-time rendering.
- Check for design-time exceptions
- Obtain the exception’s call stack and investigate the stack trace to identify the culprit. Refer to the following help topic for more information: Application Crashes or Throws an Exception.
Contact Support
This troubleshooting guide mentions the most common performance-related issues. If none of the techniques listed here apply to your application, search the web or use the DevExpress.com Search Engine. If you cannot resolve your issue, submit a ticket to our Support Center. To help us assist you efficiently, please include:
- A small, compilable test project.
- Exception details (if applicable).
- Steps to reproduce the issue.
- Expected results.
- Any relevant screenshots, videos, or other supporting materials.