Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

While developer developing 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 that the the application is laggy or slow, or if you want to make sure to squeeze the best performance out of Catel, consider taking a closer look at the checklist below is very important.

Tip

Use the ApiCop feature to get a detailed advisory report on your software

Table of Contents

General

Disable the call to LogManager.

...

AddDebugListener

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.RegisterDebugListenerAddDebugListener when releasing an application or while performance testing.

Disable event subscriptions of child values for ModelBase

To be able to (re)validate when a child object changes, the ModelBase subscribes to all change notifications (of all childs) by default. This can be disabled by using the following code:

Code Block
ModelBase.DefaultDisableEventSubscriptionsOfChildValuesValue = false;

Disabling validation during activities where validation is not required

...

Code Block
var directory = typeof(MainWindow).Assembly.GetDirectory();
AppDomain.CurrentCurrentDomain.PreloadAssemblies(directory);

...

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

Warming up the serializers

To improve performance for serialization, warm up the serializers.

MVVM

Set SkipSearchingForInfoBarMessageControl on UserControl to true

...

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

Code Block
// Use when not using styles and transitions
Catel.Windows.Controls.UserControl.DefaultTransferStylesAndTransitionsToViewModelGridValue = false; 
 
// Use when not using any validation controls
Catel.Windows.Controls.UserControl.DefaultSkipSearchingForInfoBarMessageControlValue = true;
Catel.Windows.Controls.UserControl.DefaultCreateWarningAndErrorValidatorForViewModelValue = false;
 
// Use when not using *any* validation
Catel.Data.ModelBase.SuspendValidationForAllModels = true;

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.

Implementing IDependencyPropertySelector

Catel uses a special wrapping technology to wrap bindings to dependency properties to be able to add change notifications for all target platforms. Though this technology works great, it might have impact on performance and this is not always necessary. By implementing a custom IDependencyPropertySelector, developers can tweak the interesting dependency properties per type.

Note

By default Catel subscribes to all dependency properties to not cause breaking changes

It is best to always create a default dependency instead.

Code Block
public void CustomDependencyPropertySelector : DependencyPropertySelector
{
    public override bool MustSubscribeToAllDependencyProperties(Type targetControlType)
	{
		return false;
	}
}

Then register it in the ServiceLocator:

Code Block
ServiceLocator.Default.RegisterType<IDependencyPropertySelector, CustomerDependencyPropertySelector>();

Even when the custom IDependencyPropertySelector implementation returns an empty list, Catel will always subscribe to the DataContext dependency property because it depends on thatWhen modifying a large collection of items, it is not required to raise change events for each added / removed value. Therefore the FastObservableCollection will disable change notifications until the full collection modification is done and then raise the change events just once.

Specify throttling on the ViewModelBase

...