Performance considerations

While developer software, it is very important to keep an eye on the performance. Catel itself does perform very well, but there are some caveats that you should be aware of. If you have the feeling the the application is laggy or slow, or if you want to make sure to squeeze the best performance out of Catel, the checklist below is very important.

Disable the call to LogManager.RegisterDebugListener

 The DebugListener is a very useful class while developing an application. It throws all the logging of Catel to the output window of Visual Studio which allows you to view exactly what happens behind the scenes. However, writing all these logs to the output window is very expensive and might cause an application to perform badly.

Therefore, it is important to disable any call to LogManager.RegisterDebugListener when releasing an application or while performance testing.

 Set SkipSearchingForInfoBarMessageControl on UserControl to true

By default, Catel assumes that an InfoBarMessageControl is located on any window. However, it might be that this control is not located on a window that contains an instance of the UserControl class. This might decrease the performance, especially when lots of user controls are used in a hierarchical way. The cause is that the UserControlLogic searches for an InfoBarMessageControl to register the view model to.

 If no InfoBarMessageControl is located on a container, make sure to set SkipSearchingForInfoBarMessageControl to true.

Disabling validation during activities where validation is not required

 Validation inside Catel is very powerful, but sometimes it is not needed. To disable all validation inside Catel, use the following code:

ModelBase.SuspendValidationForAllModels = true;

Use LeanAndMeanModel property on ModelBase

When loading lots of models, it is not required to get support for validation and change notifications. Notifications and validation can be suspended per model (using the LeanAndMeanModel property) or globally using the GlobalLeanAndMeanModel property.

 Use the FastObservableCollection

The FastObservableCollection does not raise events for every item, but only invokes events for the complete range of items added to or removed from the collection.

 Preloading assemblies into the AppDomain

Preloading assemblies might result in a slower startup time, but will not cause slow downs for reflection or assembly loading during the actual application execution. To preload assemblies using Catel, simply call this extension method:

WPF application

In App.xaml.cs, add the following code

var directory = typeof(MainWindow).Assembly.GetDirectory();
AppDomain.Current.PreloadAssemblies(directory);

ASP.NET application

In global.asax, add the following code:

var directory = Server.MapPath("~/bin");
AppDomain.Current.PreloadAssemblies(directory);