Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin: Experimental. Benchmark for coroutines (decoding with parallel tasks) #68

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ignaciotcrespo
Copy link
Contributor

Using coroutines to generate parts of the image in parallel shows a good performance but only for images >= 48x24, specially with 3 tasks.

Here the benchmark in my Galaxy A5. The performance increases 50% with 3 parallel tasks.

The result for 1 task is not using any coroutine.

To compare a benchmark result code without coroutines, you can use the branch https://github.com/ignaciotcrespo/blurhash/tree/benchmark-array-cacheEnabled

Galaxy A5, current version array + cache
-----------------------------------
Device: samsung - SM-A500FU
OS: Android REL - API 23
-----------------------------------
Array: true, cache: true
-----------------------------------
width: 20, height: 12
-> 10 bitmaps
<- 30 ms, Avg: 3.0 ms
-> 100 bitmaps
<- 186 ms, Avg: 1.86 ms


width: 40, height: 24
-> 10 bitmaps
<- 83 ms, Avg: 8.3 ms
-> 100 bitmaps
<- 731 ms, Avg: 7.31 ms


width: 80, height: 48
-> 10 bitmaps
<- 335 ms, Avg: 33.5 ms
-> 100 bitmaps
<- 2924 ms, Avg: 29.24 ms
Galaxy A5, using coroutines
-----------------------------------
Device: samsung - SM-A500FU
OS: Android REL - API 23
-----------------------------------

-----------------------------------
Parallel tasks: 1
-----------------------------------
width: 20, height: 12
-> 1 bitmaps
<- 5.00 ms, Avg: 5.00 ms, Max: 5.00, Min: 5.00
-> 10 bitmaps
<- 25.06 ms, Avg: 2.51 ms, Max: 7.14, Min: 1.81
-> 100 bitmaps
<- 196.96 ms, Avg: 1.97 ms, Max: 5.24, Min: 1.77


width: 40, height: 24
-> 1 bitmaps
<- 20.28 ms, Avg: 20.28 ms, Max: 20.28, Min: 20.28
-> 10 bitmaps
<- 85.42 ms, Avg: 8.54 ms, Max: 20.03, Min: 6.97
-> 100 bitmaps
<- 737.50 ms, Avg: 7.37 ms, Max: 20.15, Min: 6.86


width: 80, height: 48
-> 1 bitmaps
<- 79.84 ms, Avg: 79.84 ms, Max: 79.84, Min: 79.84
-> 10 bitmaps
<- 337.62 ms, Avg: 33.76 ms, Max: 81.32, Min: 28.03
-> 100 bitmaps
<- 2921.94 ms, Avg: 29.22 ms, Max: 79.32, Min: 28.01



-----------------------------------
Parallel tasks: 2
-----------------------------------
width: 20, height: 12
-> 1 bitmaps
<- 3.94 ms, Avg: 3.94 ms, Max: 3.94, Min: 3.94
-> 10 bitmaps
<- 26.48 ms, Avg: 2.65 ms, Max: 4.30, Min: 2.05
-> 100 bitmaps
<- 222.35 ms, Avg: 2.22 ms, Max: 5.54, Min: 1.62


width: 40, height: 24
-> 1 bitmaps
<- 12.43 ms, Avg: 12.43 ms, Max: 12.43, Min: 12.43
-> 10 bitmaps
<- 63.46 ms, Avg: 6.35 ms, Max: 15.74, Min: 4.81
-> 100 bitmaps
<- 566.36 ms, Avg: 5.66 ms, Max: 12.67, Min: 4.30


width: 80, height: 48
-> 1 bitmaps
<- 43.52 ms, Avg: 43.52 ms, Max: 43.52, Min: 43.52
-> 10 bitmaps
<- 192.24 ms, Avg: 19.22 ms, Max: 40.43, Min: 15.52
-> 100 bitmaps
<- 1725.76 ms, Avg: 17.26 ms, Max: 42.17, Min: 15.24



-----------------------------------
Parallel tasks: 3
-----------------------------------
width: 20, height: 12
-> 1 bitmaps
<- 5.10 ms, Avg: 5.10 ms, Max: 5.10, Min: 5.10
-> 10 bitmaps
<- 32.44 ms, Avg: 3.24 ms, Max: 6.40, Min: 1.94
-> 100 bitmaps
<- 241.19 ms, Avg: 2.41 ms, Max: 6.21, Min: 1.72


width: 40, height: 24
-> 1 bitmaps
<- 7.58 ms, Avg: 7.58 ms, Max: 7.58, Min: 7.58
-> 10 bitmaps
<- 47.92 ms, Avg: 4.79 ms, Max: 9.27, Min: 3.54
-> 100 bitmaps
<- 425.90 ms, Avg: 4.26 ms, Max: 7.73, Min: 3.14


width: 80, height: 48
-> 1 bitmaps
<- 38.00 ms, Avg: 38.00 ms, Max: 38.00, Min: 38.00
-> 10 bitmaps
<- 148.51 ms, Avg: 14.85 ms, Max: 36.44, Min: 11.12
-> 100 bitmaps
<- 1327.79 ms, Avg: 13.28 ms, Max: 30.85, Min: 10.78

…the opposite. What happens is the performance of multiple parallel tasks is better than 1 single task. But the performance without using coroutines is better than 1 task using coroutines. Maybe there is a way to use parallel tasks in an optimal way without using coroutines, but not sure the performance will increase too much.
@ignaciotcrespo
Copy link
Contributor Author

@hangduykhiem @connyduck here the PR to play with coroutines

@ignaciotcrespo
Copy link
Contributor Author

ignaciotcrespo commented Jun 23, 2020

Benchmark in Pixel 4, improvement ~40%, again only for big images

Pixel 4, array + cache
-----------------------------------
Device: Google - Pixel 4
OS: Android REL - API 29
-----------------------------------
Array: true, cache: true
-----------------------------------
width: 20, height: 12
-> 10 bitmaps
<- 2 ms, Avg: 0.2 ms
-> 100 bitmaps
<- 13 ms, Avg: 0.13 ms


width: 40, height: 24
-> 10 bitmaps
<- 3 ms, Avg: 0.3 ms
-> 100 bitmaps
<- 29 ms, Avg: 0.29 ms


width: 80, height: 48
-> 10 bitmaps
<- 12 ms, Avg: 1.2 ms
-> 100 bitmaps
<- 107 ms, Avg: 1.07 ms
Pixel 4, coroutines

-----------------------------------
Device: Google - Pixel 4
OS: Android REL - API 29
-----------------------------------

-----------------------------------
Parallel tasks: 1
-----------------------------------
width: 20, height: 12
-> 1 bitmaps
<- 0,28 ms, Avg: 0,28 ms, Max: 0,28, Min: 0,28
-> 10 bitmaps
<- 1,29 ms, Avg: 0,13 ms, Max: 0,25, Min: 0,08
-> 100 bitmaps
<- 9,54 ms, Avg: 0,10 ms, Max: 0,26, Min: 0,08


width: 40, height: 24
-> 1 bitmaps
<- 0,78 ms, Avg: 0,78 ms, Max: 0,78, Min: 0,78
-> 10 bitmaps
<- 3,66 ms, Avg: 0,37 ms, Max: 0,72, Min: 0,31
-> 100 bitmaps
<- 32,03 ms, Avg: 0,32 ms, Max: 0,70, Min: 0,31


width: 80, height: 48
-> 1 bitmaps
<- 2,65 ms, Avg: 2,65 ms, Max: 2,65, Min: 2,65
-> 10 bitmaps
<- 13,89 ms, Avg: 1,39 ms, Max: 2,68, Min: 1,22
-> 100 bitmaps
<- 111,27 ms, Avg: 1,11 ms, Max: 2,66, Min: 1,02



-----------------------------------
Parallel tasks: 2
-----------------------------------
width: 20, height: 12
-> 1 bitmaps
<- 0,65 ms, Avg: 0,65 ms, Max: 0,65, Min: 0,65
-> 10 bitmaps
<- 2,00 ms, Avg: 0,20 ms, Max: 0,33, Min: 0,15
-> 100 bitmaps
<- 17,42 ms, Avg: 0,17 ms, Max: 1,88, Min: 0,11


width: 40, height: 24
-> 1 bitmaps
<- 0,62 ms, Avg: 0,62 ms, Max: 0,62, Min: 0,62
-> 10 bitmaps
<- 2,92 ms, Avg: 0,29 ms, Max: 0,61, Min: 0,24
-> 100 bitmaps
<- 32,25 ms, Avg: 0,32 ms, Max: 1,07, Min: 0,23


width: 80, height: 48
-> 1 bitmaps
<- 3,36 ms, Avg: 3,36 ms, Max: 3,36, Min: 3,36
-> 10 bitmaps
<- 10,33 ms, Avg: 1,03 ms, Max: 3,85, Min: 0,69
-> 100 bitmaps
<- 78,82 ms, Avg: 0,79 ms, Max: 1,84, Min: 0,68



-----------------------------------
Parallel tasks: 3
-----------------------------------
width: 20, height: 12
-> 1 bitmaps
<- 0,30 ms, Avg: 0,30 ms, Max: 0,30, Min: 0,30
-> 10 bitmaps
<- 5,04 ms, Avg: 0,50 ms, Max: 3,20, Min: 0,12
-> 100 bitmaps
<- 21,17 ms, Avg: 0,21 ms, Max: 2,86, Min: 0,11


width: 40, height: 24
-> 1 bitmaps
<- 0,84 ms, Avg: 0,84 ms, Max: 0,84, Min: 0,84
-> 10 bitmaps
<- 3,45 ms, Avg: 0,34 ms, Max: 0,71, Min: 0,24
-> 100 bitmaps
<- 28,81 ms, Avg: 0,29 ms, Max: 0,99, Min: 0,19


width: 80, height: 48
-> 1 bitmaps
<- 1,13 ms, Avg: 1,13 ms, Max: 1,13, Min: 1,13
-> 10 bitmaps
<- 8,11 ms, Avg: 0,81 ms, Max: 1,62, Min: 0,50
-> 100 bitmaps
<- 61,50 ms, Avg: 0,61 ms, Max: 2,54, Min: 0,49

mrousavy added a commit to mrousavy/react-native-blurhash that referenced this pull request Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants