wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Performance delay when filtering a DataTable using the DefaultView.RowFilter property

Open SreemonPremkumarMuthukrishnan opened this issue 1 year ago • 4 comments

Description

When filtering the DataTable using the DefaultView.RowFilter property, it takes a long time (more than 2 minutes) to apply the filter. The number of items being filtered is 5,800. Please find the code snippet below.

Note: The filter string was provided along with the sample.

C# code:

private void FilteringButton_Click(object sender, RoutedEventArgs e)
{
    DataTable dataTable = getDataReturn();
    var filterString = File.ReadAllText(@"..\..\Filterstring.txt");
    dataTable.DefaultView.RowFilter = filterString;
}

Output reference:

https://github.com/user-attachments/assets/d4e746c9-d665-4c53-b3c0-76f6167296f9

Sample:

DataTable_Filtering_Demo.zip

Reproduction Steps

  1. Run the sample
  2. Click the "Click to filter" button to filter

Expected behavior

The filter should not take too much time.

Actual behavior

The filtering takes too much time.

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

This is unrelated to WPF, DataTable and its oddities belong to https://github.com/dotnet/runtime

Looking at the "filter", I'm not that surprised tbh though. This is close to getting StackOverflowException, x86 probably will.

See, that's the func you're gonna get stuck at. https://github.com/dotnet/runtime/blob/1337553ef2f1cb7a78bb1c19a85b8a9c929064b2/src/libraries/System.Data.Common/src/System/Data/Filter/BinaryNode.cs#L283

h3xds1nz avatar Aug 01 '24 20:08 h3xds1nz

Hi,

Is there any way you know of to improve or optimize the performance of filtering in a DataTable? Specifically, I am looking for methods or best practices that can enhance efficiency and reduce the processing time for large datasets.

As @h3xds1nz said you need to be asking about these classes over at https://github.com/dotnet/runtime

miloush avatar Aug 07 '24 19:08 miloush

Try IN operator instead. dataView.RowFilter = "[LastName] IN ('10002car', '10010car', '10021car')";

omariom avatar Aug 11 '24 10:08 omariom