-
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
Draft
ejona86
wants to merge
2
commits into
grpc:master
Choose a base branch
from
ejona86:r8-service-loader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load() unused since c8a94d1 in 2020.
agrieve
reviewed
Oct 9, 2025
0a3be77 to
905aeb7
Compare
Member
Author
|
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());
+ //}
}
/** |
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.
905aeb7 to
14c4a25
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Just a sketch, but the neat thing is if we trigger the ServiceLoader optimization, that will keep the constructors for us, so we could use the hard-coded list or the fake-ServiceLoader-iterator and it should work fine either way.