i have been tasked with updating some legacy code and really need to decrease the run time on part of it. The below list is loaded quite often. I have managed to reduce the time from about a minute to around fifteen seconds, but it really needs to go down further. The following lines of code work fairly well, but I am trying to squeeze everything I can out of it.
List<MyObject> _moList = new List<MyObject>(DB.GetAll(queryString, parameters, MyObject.Extract));
_moList.AsParallel().ForAll(s => s.RelativeCost = GetRelativeCost(s));
So I have a few questions. First, is it possible to combine those two lines into one line, and if so, how? Second, would doing this improve the performance at all?
Some items of not are that MyObject has around forty properties (not sure if that is pertinent or not) and GetRelativeCost is somewhat expensive when it comes to time/cpu cycles (hence the parallel run).
Any help would be greatly appreciated!
P.S. I am working other angles too, in particular trying to reduce the "cost" of GetRelativeCost, but I need to get every cycle I can get out of this to make it acceptable to the user.