Go to the Help menu in Visual Studio. From there you can send feedback. First search for existing feedback relative to the problem. I am currently unable to search; Microsoft won't sign me in plus I am using VS 2017.
WPF DataGrid - SelectAll performance is erratic
I'm encountering a problem where I have a WPF DataGrid bound to a List of structs. If I use SelectAll to select all the rows, sometimes it highlights all the rows instantly regardless if there are hundreds of thousands, and sometimes (with exactly the same data) the SelectAll can take minutes or longer. It's very strange - I can execute the same program again and again with the same data but the SelectAll performance is hugely erratic.
If no one has ever heard of this, I'll try to reproduce it in some code, but it's annoyingly random and thus hard to reproduce. Thanks.
Windows Presentation Foundation
XAML
-
Sam of Simple Samples 5,516 Reputation points
2021-08-26T23:12:06.867+00:00 Is there any data that might require extra processing? Are you sure there is not other processing occurring in the system that could cause it?
-
Steve Williams 26 Reputation points
2021-08-27T07:33:16.287+00:00 Hi, thanks for the comment. I use a List of structs as the performance in a DataGrid (excluding SelectAll obviously) seems better in comparison to an ObservableCollection. As a test I tried switching to ObservableCollection and also tried a List of classes but the issue with SelectAll remains. It's maddening! I feel like I've checked everything I can check. There's no other processing or threads running. As far as I know, SelectAll runs on the UI thread, so the UI pauses while it does its work. Sometimes that pause is instant, even with (say) 200,000 rows or more. Other times it takes 10 seconds to select just 30,000 rows. The data rows are not particularly wide (12 columns, a mix of int and strings), and I tried it with a reduced set of columns, but it still exhibits the problem. But only sometimes... which is the annoying part. There's no pattern to it - I can run it with exactly the same data again and again, and the problem pops up every few executions, and it happens in both debug and release mode. I'm targeting .NET 4.6.2 and running a pretty good machine, Ryzen 3950 with 32GB memory, no issues with anything else. I even spun up a VM to see if it was something with my environment. The VM was a basic install of Windows 10, but same problem there too. I can't seem to find anyone having similar issues.
-
Viorel 112.5K Reputation points
2021-08-27T08:55:06.523+00:00 If you have a sample project, which shows the problem and includes a DataGrid and a large list of some data, you can publish it on your OneDrive or other services.
-
Steve Williams 26 Reputation points
2021-08-27T13:00:31.78+00:00 Thanks, I've made a very simple example and put it on Google Drive and documented the code. Any help would be appreciated!
https://drive.google.com/file/d/1_9d2aIPsTAWK5xVIF8xWIc6dlYGohncN/view?usp=sharing
-
Steve Williams 26 Reputation points
2021-08-27T13:01:10.103+00:00 Simple example here, on Google Drive and documented the code. Any help would be appreciated!
https://drive.google.com/file/d/1_9d2aIPsTAWK5xVIF8xWIc6dlYGohncN/view?usp=sharing
-
Sam of Simple Samples 5,516 Reputation points
2021-08-27T17:54:03.99+00:00 I tried your example and I get poor performance every time I select all and each time I select a row after a select all. There are others reporting poor performance in similar situations and I see no easy answer.
-
Steve Williams 26 Reputation points
2021-08-27T19:54:49.737+00:00 Yes it's quite odd. Frustrating because there are times when a random alteration to the struct can seemingly fix it. I say seemingly, because it's intermittent. In my main application, I tried again to switch to a class instead of a struct but the problem just won't go away. Minor changes to the struct give different results. Anyway, thanks for giving it your attention.
-
Viorel 112.5K Reputation points
2021-08-27T20:10:37.13+00:00 I think that DataGrid was designed for universal case, and it uses object variables in its implementation. Therefore, this results in frequent “boxing” of struct values.
The issue of uncoloured (unselected) rows is probably caused by the problem of comparison operation, which works specifically in case of items that are boxed multiple times. For this reason, you should avoid using struct.
-
Sam of Simple Samples 5,516 Reputation points
2021-08-27T21:02:49.767+00:00 I consistently get poor performance. Also, I removed my previous comment about structs; I do not know why I thought that was strange.
-
Steve Williams 26 Reputation points
2021-08-28T19:39:19.2+00:00 This seems quite reasonable to me, thanks. I'll make a switch to classes instead, although I know that seems to have the same performance issue with SelectAll too, although it does fix that uncoloured rows problem.
-
Törkel, Bastian 6 Reputation points
2021-09-06T13:35:59.87+00:00 Hello, I have the same issue here on .Net 4.8
I found out two things:
- If the window with the DataGrid opens and the only thing I do is to click in the Grid and Ctrl+a, everything is fine.
If I do anything else e.g. open a dropdown, then the selection is slow. - If I overwrite the Equals() method inside my entry objects, I can see in the debugger that it gets called a lot in that time
I'm not 100% sure, but maybe that is the same problem and in that case this information might help?
And I would be happy, if a solution can get found for this. Even if I have to overwrite the observable collection. - If the window with the DataGrid opens and the only thing I do is to click in the Grid and Ctrl+a, everything is fine.
-
Steve Williams 26 Reputation points
2021-09-09T19:43:29.103+00:00 Hi, yes I tried it on 4.8 too and it's the same problem. I have a request with Microsoft, so maybe they will get back to us:
-
vikash gupta 1 Reputation point
2022-08-17T09:04:42.397+00:00 @ ShmoofySoft , are you able to solve this issue ? I am facing same issue .
Please suggest solution here if any . -
Viorel 112.5K Reputation points
2022-08-17T09:21:59.937+00:00 If you are facing the same issue, then consider using classes instead of structures.
Sign in to comment
-
Sam of Simple Samples 5,516 Reputation points
2021-08-27T20:57:13.17+00:00 -
Steve Williams 26 Reputation points
2021-08-28T19:40:02.893+00:00 Job done, thanks. Be interesting to see what comes out of it.
Sign in to comment -