Last post Apr 30, 2014 09:46 AM by markfitzme
Apr 01, 2013 11:48 AM|marko.pa|LINK
I am working on some refactoring and code optimization to improve performace. The current solution was done by using a lots of nested foreach loops and I'm planning to use Tasks.Parallel features to do that. Here is my pseudo code:
foreach(item in colection)
foreach(item2 in collection2)
foreach(item3 in collection3)
foreach(item4 in collection4)
I've read this post: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2e0652fa-c916-4644-bf52-4d7bd4aa1761/ which was very useful!
Now, my question is: Where should I start from, the most inner loop or the most outer loop? What is the safest aproach in terms of threading issues you can run into?
Or if anybody else has ever done something similar, any suggestion or comment is much appreciated!
Apr 29, 2014 08:03 PM|dahla|LINK
it all depends on the relations between the content of the loops. if the inner loops are dependent on values from the outler loops, then off course you new to await the tasks for the outer loops to be completed first
Apr 30, 2014 01:54 AM|Paul Linton|LINK
Start with the code that you have measured to be slow. How long does it take? What do you need its runtime to be?
Best advice on performance
Apr 30, 2014 09:46 AM|markfitzme|LINK
This looks to be a On3 (big O of n cubed) which should be very bad performance wise. That's a lot of database calls in rapid succession and a good chance of running out of connections in the pool if garbage collection is not handled well.