Skip to content

Commit facf576

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
Restrict brotli usage to devices with more than 2 physical cores
For us it doesn't really matter amount of cores available for us. We need only physical cores count as we use it for filtering weak devices. _SC_NPROCESSORS_CONF - amount of physical cores (android devices doesn't have extrnal cpu cores hotplug). **Used** _SC_NPROCESSORS_ONLN - amount of cores available for OS right now. Often smaller than _SC_NPROCESSORS_CONF because OS can deactivate cores for powersave Runtime.getRuntime().availableProcessors() - a core count available to jvm. Has the same limitations as _SC_NPROCESSORS_ONLN but also can be decreased because some cores are allocated to other more priority processes (?)
1 parent 985b302 commit facf576

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

app/src/main/java/org/schabi/newpipe/DownloaderImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.schabi.newpipe;
22

33
import android.content.Context;
4+
import android.system.Os;
5+
import android.system.OsConstants;
46

57
import androidx.annotation.NonNull;
68
import androidx.annotation.Nullable;
@@ -43,13 +45,20 @@ public final class DownloaderImpl extends Downloader {
4345
private final OkHttpClient client;
4446

4547
private DownloaderImpl(final OkHttpClient.Builder builder) {
48+
final CompressionInterceptor compressionInterceptor;
49+
if (Os.sysconf(OsConstants._SC_NPROCESSORS_CONF) > 2) {
50+
compressionInterceptor = new CompressionInterceptor(
51+
Brotli.INSTANCE,
52+
Gzip.INSTANCE);
53+
} else {
54+
compressionInterceptor = new CompressionInterceptor(
55+
Gzip.INSTANCE);
56+
}
4657
this.client = builder
4758
.readTimeout(30, TimeUnit.SECONDS)
4859
// .cache(new Cache(new File(context.getExternalCacheDir(), "okhttp"),
4960
// 16 * 1024 * 1024))
50-
.addInterceptor(new CompressionInterceptor(
51-
Brotli.INSTANCE,
52-
Gzip.INSTANCE))
61+
.addInterceptor(compressionInterceptor)
5362
.build();
5463
this.mCookies = new HashMap<>();
5564
}

0 commit comments

Comments
 (0)