Performance Issues with Validation, when validating complex Graphs #997

Open
opened 2026-01-29 17:47:32 +00:00 by claunia · 0 comments
Owner

Originally created by @uflowie on GitHub (Sep 28, 2023).

Describe the bug
When using an EditContext for validating a graph, we have run into the following issue: Some Components, most noticably Dropdowns and Datepickers produce some performance issues when a property in a child of the graph is bound. For example, given a graph like:

public class Company
{
  public Employee { get; set; }
}

public class Employee
{
  public DateTime BirthDate { get; set; }
}

when binding to the BirthDate of an Employee within an EditContext that has the Company as a Model, calling NotifyValidationStateChanged on the EditContext repeatedly will progressively make the site slower. This is because of the following code in the RadzenDatePicker (line 956-961):

if (EditContext != null && ValueExpression != null && FieldIdentifier.Model != EditContext.Model)
{
    FieldIdentifier = FieldIdentifier.Create(ValueExpression);
    EditContext.OnValidationStateChanged += ValidationStateChanged;
}

In this constellation the line causes the component to hook into EditContext.OnValidationStateChanged every single time the component has its parameters set without unregistering the previous callback, because the condition FieldIdentifier.Model != EditContext.Model is always met. As a consequence, the component will rerender +1 times every single time it has its parameters set whenever EditContext.NotifyValidationStateChanged is fired. I suggest storing the model of the FieldIdentifier locally instead of comparing it with the Model of the EditContext.

Expected behavior
Whether i bind to the model of the EditContext or some property of a child of that model (or any other model for that matter) should have no bearing on the performance of these components.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome (latest)
  • Version: latest
Originally created by @uflowie on GitHub (Sep 28, 2023). **Describe the bug** When using an EditContext for validating a graph, we have run into the following issue: Some Components, most noticably Dropdowns and Datepickers produce some performance issues when a property in a child of the graph is bound. For example, given a graph like: ```csharp public class Company { public Employee { get; set; } } public class Employee { public DateTime BirthDate { get; set; } } ``` when binding to the BirthDate of an Employee within an EditContext that has the Company as a Model, calling NotifyValidationStateChanged on the EditContext repeatedly will progressively make the site slower. This is because of the following code in the RadzenDatePicker (line 956-961): ```csharp if (EditContext != null && ValueExpression != null && FieldIdentifier.Model != EditContext.Model) { FieldIdentifier = FieldIdentifier.Create(ValueExpression); EditContext.OnValidationStateChanged += ValidationStateChanged; } ``` In this constellation the line causes the component to hook into EditContext.OnValidationStateChanged every single time the component has its parameters set without unregistering the previous callback, because the condition `FieldIdentifier.Model != EditContext.Model` is always met. As a consequence, the component will rerender +1 times every single time it has its parameters set whenever EditContext.NotifyValidationStateChanged is fired. I suggest storing the model of the FieldIdentifier locally instead of comparing it with the Model of the EditContext. **Expected behavior** Whether i bind to the model of the EditContext or some property of a child of that model (or any other model for that matter) should have no bearing on the performance of these components. **Desktop (please complete the following information):** - OS: Windows 10 - Browser: Chrome (latest) - Version: latest
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#997