dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.06k stars 1.17k forks source link

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

Open SreemonPremkumarMuthukrishnan opened 2 months ago

SreemonPremkumarMuthukrishnan commented 2 months ago

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

h3xds1nz commented 2 months ago

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

SreemonPremkumarMuthukrishnan commented 2 months ago

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.

miloush commented 2 months ago

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

omariom commented 2 months ago

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