You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-5Lines changed: 13 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# Parallel coroutine operations on Kotlin collections
2
-
Provides parallelized map, ~~reduce~~, ~~etc.~~ operations using coroutines in Kotlin.
2
+
Provides parallelized map, reduce, etc. operations using coroutines in Kotlin.
3
3
4
4
At this point, there is only a parallel map implementation called .mapParallel(). It is implemented like this.
5
5
```kotlin
@@ -19,6 +19,17 @@ fun showCase() {
19
19
```
20
20
If you want to achieve multithreading, make sure to run the coroutine with the Default dispatcher.
21
21
22
+
## Chunked operations
23
+
Chunked operations improve performance since they split the collection into just a couple of segments,
24
+
which are processed each by a single thread. That benefits from data locality and lesser thread management.
25
+
It is particularly useful (pretty much needed for operations like sum) in the reduce operation when using multithreading,
26
+
since each thread takes one chunk that it reduces on its own. After all threads finish, their results are then reduced again to the final result.
27
+
28
+
## Benchmarks
29
+
This source includes some benchmarks in the test source folder using [JUnitBenchmarks](http://labs.carrotsearch.com/junit-benchmarks-tutorial.html). Performance of the methods (chunked vs. not chunked and Dispatcher.Default vs Dispatcher.Main) depends on the type of the transformation operation (whether it's blocking for a long time, suspending or really quick).
30
+
31
+
Example benchmarks will be included here soon.
32
+
22
33
## Gradle
23
34
To include this in you gradle project add the following to you root build.gradle file.
24
35
```gradle
@@ -37,7 +48,4 @@ dependencies {
37
48
```
38
49
39
50
## Future
40
-
In the future, I would like parallel reduce and other transformation functions to be implemented,
41
-
as well as chunked variations of the map and future operations.
42
-
Chunked operations could potentially improve performance since they would split the collection into just a couple of segments,
43
-
which would be processed each by a single thread. That could benefit from data locality and lesser thread management.
51
+
In the future, I would like other transformation functions to be implemented.
0 commit comments