AOMediaCodec / libavif

libavif - Library for encoding and decoding .avif files
Other
1.58k stars 206 forks source link

android_jni: Set threads to 2 instead of CPU count #2472

Closed vigneshvg closed 1 month ago

vigneshvg commented 1 month ago

Empirically, on Android devices with more than 1 core, it is almost always better to use 2 threads than to use number_of_cpu_cores threads.

Update the public java API function documentation to reflect this change.

The new behavior is:

This change ensures that users who use the library via JNI take the optimal path when using the default value of 0.

wantehchang commented 1 month ago

In Chrome's avif_image_decoder.cc, I also set libavif's maxThreads parameter to the hardcoded value of 2. I have two reasons:

  1. Almost all computers are multicore today, so I just assume a multicore computer. Not using more than two cores avoids the performance core vs. efficiency core issue we observed when working on libgav1 multithreading.
  2. Chrome is likely to decode many images at the same time, so it does not make sense to use many cores for each image.
vigneshvg commented 1 month ago

In Chrome's avif_image_decoder.cc, I also set libavif's maxThreads parameter to the hardcoded value of 2. I have two reasons:

  1. Almost all computers are multicore today, so I just assume a multicore computer. Not using more than two cores avoids the performance core vs. efficiency core issue we observed when working on libgav1 multithreading.
  2. Chrome is likely to decode many images at the same time, so it does not make sense to use many cores for each image.

Yes, this change is also along the same lines. The only difference is that there are several low-end Android devices in the market which are single core. So i chose min(core_count, 2) as the default value instead of always 2.