Performance linq orderby.tolist ()

I have a sequencing request to a list and get called many times. list = list.OrderBy().ToList(); In this code, the ToList () method spends a lot of resources and takes a lot of time. How can I speed up working with another sorting method without converting to a list. Should I use the .Sort extension for arrays?

+4
source share
2 answers

First of all, try sorting the list once and save it.

To speed things up, you can use Parallel LINQ.

see http://msdn.microsoft.com/en-us/magazine/cc163329.aspx

The OrderBy () Parallel parameter is as follows:

  var query = data.AsParallel().Where(x => p(x)).Orderby(x => k(x)).ToList(); 
+5
source

You only need to call ToList () only once to get a sorted list. All future actions should use sortedList.

 sortedList = list.OrderBy().ToList(); 
0
source

Source: https://habr.com/ru/post/1339744/


All Articles