![]() When we take a closer look at where we lose time, it was clear that a lot of time was spent waiting. The simplified version of the initial code looked like this.Ī simple iteration over a list, and within the loop, the migration of an item where we: That's a lot of time, especially if you know that it isn't a difficult task to migrate an item. It took 30 minutes to process 1.000 items, which makes it 30 hours in total to process all of the items in the collection. Initial codeįor our case, we had 60.000 items that had to be migrated from one system to another system. In this article, we'll take a look at the different ways to process a collection faster. In data parallel operations, the source collection is partitioned so that multiple threads can operate on different segments concurrently. It's also safe to say that the chance of bugs within this code is far less in comparison with a custom implementation.ĭata parallelism refers to scenarios in which the same operation is performed concurrently (that is, in parallel) on elements in a source collection or array. Luckily, C# hides all of the implementation details for us with the Task Parallel Library (TPL) introduced in. It even gets more complex when you spawn multiple threads to achieve the best performance. If you take a look at the thread docs you can see that it takes some "orchestration code" to manage these threads.īecause we write the code on your own, there's also a probability that this code contains bugs. NET, spawning new threads was manual work and required some knowledge. When you want to work through a collection faster, a common solution is to divide the work among threads that run concurrently. ![]() The same applies to programming, where these friends are called threads. ![]() But with a couple of friends, the same amount of work can be completed in an hour or less, depending on the number of friends that are helping and how hard everyone is working. When you have a chore that takes a long time to complete then it's probably going to be faster if you can divide the amount of work.įor example, if you paint a room on your own, this job might take a couple of hours. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |