From the course: Scala Essential Training for Data Science (2017)

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

When and when not to use parallel collections

When and when not to use parallel collections - Scala Tutorial

From the course: Scala Essential Training for Data Science (2017)

When and when not to use parallel collections

- [Instructor] Here are some things to keep in mind when considering the use of parallel collections. First of all, parallel collections should be considered only when you have at least thousands, possibly tens of thousands of elements. For some types of collections, converting between the sequential and parallel type requires copying data, so keep that in mind. Now you want to avoid side effects. It's best to avoid applying procedures with side effects in parallel collections. Side effects can lead to nondeterminism. That means different times you execute the operation you may get different ordering of results. And side effects could take affect in different orders each time the operation is executed. Also you want to avoid nonassociative operations when working with parallel collections. In associative operations, the order of operations doesn't matter. Now if your computation depends on state information as you go through the processing of a collection, and the order of that…

Contents