-
Notifications
You must be signed in to change notification settings - Fork 4k
Trigger R8's ServiceLoader optimization #12414
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
base: master
Are you sure you want to change the base?
Conversation
0a3be77 to
905aeb7
Compare
|
I proved this works with R8 with optimizations by looking at the dex results. I am keeping it as draft as I need to investigate some potential runtime issues it might cause inside Google due to how the build is structured (related to cl/856425076). My hacks to get proguard-android-optimize.txt limping along: diff --git a/android-interop-testing/build.gradle b/android-interop-testing/build.gradle
index 17551465f..cb376e013 100644
--- a/android-interop-testing/build.gradle
+++ b/android-interop-testing/build.gradle
@@ -47,7 +47,7 @@ android {
debug { minifyEnabled false }
release {
minifyEnabled true
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
lintOptions {
@@ -78,10 +78,10 @@ dependencies {
libraries.androidx.test.rules,
libraries.opencensus.contrib.grpc.metrics
- implementation (project(':grpc-services')) {
- exclude group: 'com.google.protobuf'
- exclude group: 'com.google.guava'
- }
+ //implementation (project(':grpc-services')) {
+ // exclude group: 'com.google.protobuf'
+ // exclude group: 'com.google.guava'
+ //}
androidTestImplementation 'androidx.test.ext:junit:1.1.3',
'androidx.test:runner:1.4.0'
diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java
index a9ee93824..bfd03b08e 100644
--- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java
+++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java
@@ -28,8 +28,8 @@ import io.grpc.ServerInterceptor;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.internal.LogExceptionRunnable;
-import io.grpc.services.CallMetricRecorder;
-import io.grpc.services.MetricRecorder;
+//import io.grpc.services.CallMetricRecorder;
+//import io.grpc.services.MetricRecorder;
import io.grpc.stub.ServerCallStreamObserver;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.integration.Messages.Payload;
@@ -65,20 +65,20 @@ public class TestServiceImpl implements io.grpc.BindableService, AsyncService {
private final ScheduledExecutorService executor;
private final ByteString compressableBuffer;
- private final MetricRecorder metricRecorder;
+ private final Object metricRecorder;
final Semaphore lock = new Semaphore(1);
/**
* Constructs a controller using the given executor for scheduling response stream chunks.
*/
- public TestServiceImpl(ScheduledExecutorService executor, MetricRecorder metricRecorder) {
+ public TestServiceImpl(ScheduledExecutorService executor, Object metricRecorder) {
this.executor = executor;
this.compressableBuffer = ByteString.copyFrom(new byte[1024]);
this.metricRecorder = metricRecorder;
}
public TestServiceImpl(ScheduledExecutorService executor) {
- this(executor, MetricRecorder.newInstance());
+ this(executor, null);//MetricRecorder.newInstance());
}
@Override
@@ -139,25 +139,25 @@ public class TestServiceImpl implements io.grpc.BindableService, AsyncService {
responseObserver.onCompleted();
}
- private static void echoCallMetricsFromPayload(TestOrcaReport report) {
- CallMetricRecorder recorder = CallMetricRecorder.getCurrent()
- .recordCpuUtilizationMetric(report.getCpuUtilization())
- .recordMemoryUtilizationMetric(report.getMemoryUtilization());
- for (Map.Entry<String, Double> entry : report.getUtilizationMap().entrySet()) {
- recorder.recordUtilizationMetric(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, Double> entry : report.getRequestCostMap().entrySet()) {
- recorder.recordRequestCostMetric(entry.getKey(), entry.getValue());
- }
+ private static void echoCallMetricsFromPayload(TestOrcaReport unused) {
+ //CallMetricRecorder recorder = CallMetricRecorder.getCurrent()
+ // .recordCpuUtilizationMetric(report.getCpuUtilization())
+ // .recordMemoryUtilizationMetric(report.getMemoryUtilization());
+ //for (Map.Entry<String, Double> entry : report.getUtilizationMap().entrySet()) {
+ // recorder.recordUtilizationMetric(entry.getKey(), entry.getValue());
+ //}
+ //for (Map.Entry<String, Double> entry : report.getRequestCostMap().entrySet()) {
+ // recorder.recordRequestCostMetric(entry.getKey(), entry.getValue());
+ //}
}
private void echoMetricsFromPayload(TestOrcaReport report) {
- metricRecorder.setCpuUtilizationMetric(report.getCpuUtilization());
- metricRecorder.setMemoryUtilizationMetric(report.getMemoryUtilization());
- metricRecorder.setAllUtilizationMetrics(new HashMap<>());
- for (Map.Entry<String, Double> entry : report.getUtilizationMap().entrySet()) {
- metricRecorder.putUtilizationMetric(entry.getKey(), entry.getValue());
- }
+ //metricRecorder.setCpuUtilizationMetric(report.getCpuUtilization());
+ //metricRecorder.setMemoryUtilizationMetric(report.getMemoryUtilization());
+ //metricRecorder.setAllUtilizationMetrics(new HashMap<>());
+ //for (Map.Entry<String, Double> entry : report.getUtilizationMap().entrySet()) {
+ // metricRecorder.putUtilizationMetric(entry.getKey(), entry.getValue());
+ //}
}
/** |
905aeb7 to
14c4a25
Compare
This simplifies R8 Full Mode's configuration when paired with R8 optimizations (which is made more difficult to avoid in AGP 9), as when the optimization is triggered Full Mode will automatically keep the constructor for the relevant classes. android-interop-test doesn't currently enable R8 optimizations, so it doesn't actually demonstrate the benefit, but I have manually confirmed that enabling proguard-android-optimize.txt does cause the ServiceLoader optimization in android-interop-test. Note that full mode is a separate configuration and not necessary to get the ServiceLoader optimization.
77fd613 to
3ddb0f6
Compare
|
I think the internal-to-Google pieces are fine after cl/859616448. I'll do more testing, but my main concern in resolved. |
This simplifies R8 Full Mode's configuration when paired with R8
optimizations (which is made more difficult to avoid in AGP 9), as when
the optimization is triggered Full Mode will automatically keep the
constructor for the relevant classes.
android-interop-test doesn't currently enable R8 optimizations, so it
doesn't actually demonstrate the benefit, but I have manually confirmed
that enabling proguard-android-optimize.txt does cause the ServiceLoader
optimization in android-interop-test. Note that full mode is a separate
configuration and not necessary to get the ServiceLoader optimization.