I am trying to improve the performances of a game by parallelizing some code. One of the bottlenecks I have regards this sorting function:
_list.Sort((obj1, obj2) => obj1.Distance.CompareTo(obj2.Distance));
The variable _list
is a List<Object>
.
There is a way to parallelize this?
More information: Distance
is a float
, computed as Vector3.Distance()
. It is backed in a private field. It's not computed every time it is read. I need to sort all the list, not only a part of it. The list contains at maximum 1000/1500 objects. In the worst case, from the tests I did, takes between 7 and 10 ms (from what I can see looking in the profiler using the deep profile). The list in the worst case is completely unsorted, is not something I can control.