Does [Cascadingparameter] Affect Performance in Comparison with [Parameter]?

Does [Cascadingparameter] Affect Performance in Comparison with [Parameter]?

I have a GridCell component, which will be instantiated thousands of times.

The component requires access to its parent components (GridRow and Grid). Value of those parameters should never change.

How does following alternatives compare in terms of performace?

  1. Using CascadingParametes

    GridCell:

    [CascadingParameter(Name = "DataGrid")] DataGrid DataGrid { get; set; }
    [CascadingParameter(Name = "Row")] DataGridRow Row { get; set; }
    

    usage in GridRow:

    <Cell />
    
  2. Parameters

    GridCell:

    [Parameter] DataGrid DataGrid { get; set; }
    [Parameter] DataGridRow Row { get; set; }
    

    usage in GridRow:

    <Cell DataGrid="@Grid" Row="@this" >
    
3

1 Answer

It depends on IsFixed attribute:

<CascadingValue Value="this" IsFixed="true">
    <SomeOtherComponents>
</CascadingValue>
  • If the IsFixed value is false (the default), then every recipient of the cascaded value sets up a subscription to receive change notifications. In this case, each [CascadingParameter] is substantially more expensive than a regular [Parameter] due to the subscription tracking.
  • If the IsFixed value is true (for example, <CascadingValue Value="@someValue" IsFixed="true"> ), then receipients receive the initial value but do not set up any subscription to receive updates. In this case, each [CascadingParameter] is lightweight and no more expensive than a regular [Parameter].

Learn about this topic and other performance topics at Ensure cascading parameters are fixed MS docs.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.