Skip to content

Commit 1a46bb8

Browse files
authored
perf(r8): drop the protobuf and gRPC server keep rules (#1370)
* perf(r8): drop the protobuf and gRPC server keep rules `-keep class * extends GeneratedMessageLite { *; }` and its $Builder twin pinned 29,633 items — 94% of the app's entire keep radius — and blocked R8 from optimizing 24,909 methods, 81% of every method it was forbidden to touch. Both are replaced by a field-only rule that now ships inside com.flipcash:{ocp,flipcash2}-client-protocol, where the generated messages live. javalite resolves fields reflectively and reaches builders and message methods from ordinary call sites, so the methods never needed keeping. `-keep class * implements io.grpc.BindableService { *; }` goes with them. All 45 matches were *ImplBase and *CoroutineImplBase server skeletons generated alongside the client stubs; nothing in an Android client implements a gRPC service, and no other rule kept them, so R8 can now delete them outright. Measured by the R8 configuration analyzer, before and after: live methods 230,686 -> 205,144 (-25,542) live classes 42,338 -> 41,770 (-568) live fields 96,939 -> 95,692 (-1,247) obfuscation score 89.0% -> 96.1% optimization score 89.3% -> 96.3% shrinking score 89.1% -> 96.1% The AbstractStub rule stays for now. It pins 114 classes with all members and the stubs are reached from generated newStub() factories, so it is very likely removable too, but that one needs a run on a device rather than a static argument. Merges after both contract packages publish the rule; the pinned versions in libs.versions.toml have to carry it first. * build(deps): take the contract packages at 0.3.0 for their keep rules 0.3.0 is the first release of either package to ship META-INF/proguard/*.pro alongside its generated messages, which is what makes the removal of the app's own protobuf rules in this branch safe. Both jars on Central carry the rule; R8 reads it straight out of the dependency. Pinning the version and dropping the local rules in one change keeps the app from ever sitting on a commit with no protobuf keep rule at all.
1 parent efbe3e7 commit 1a46bb8

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎apps/flipcash/app/proguard-rules.pro‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
-keepnames class com.flipcash.app.core.AppRoute
88
-keepnames class com.flipcash.app.core.AppRoute$**
99

10-
# Protobuf — keep all generated message classes and their builders.
11-
# Using type-hierarchy rules so new packages / updated gRPC stubs are
12-
# caught automatically instead of listing every gen package.
13-
-keep class * extends com.google.protobuf.GeneratedMessageLite { *; }
14-
-keep class * extends com.google.protobuf.GeneratedMessageLite$Builder { *; }
10+
# Protobuf keep rules ship with the contract packages themselves, from 0.3.0 on:
11+
# com.flipcash:{ocp,flipcash2}-client-protocol carry them in META-INF/proguard/, which
12+
# R8 reads straight out of the jar. Downgrading either pin below 0.3.0 silently removes
13+
# the app's only protobuf keep rule.
1514

16-
# gRPC — keep generated service stubs (abstract + concrete)
15+
# gRPC — keep the generated client stubs
1716
-keep class * extends io.grpc.stub.AbstractStub { *; }
18-
-keep class * implements io.grpc.BindableService { *; }
1917

2018
# Keep our scan classes that interact with native. The scanner's JNI constructs
2119
# these from C++ by name (FindClass("com/kik/scan/UsernameKikCode"), GetMethodID

‎gradle/libs.versions.toml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ protovalidate-kt = "0.1.1"
6666
# Generated client SDKs for the two backend contracts. Separate versions on purpose: the
6767
# protos are independent (flipcash2 does not import ocp), so the packages move on their own
6868
# cadence and there is nothing to keep aligned.
69-
ocp-client-protocol = "0.2.0"
70-
flipcash2-client-protocol = "0.2.0"
69+
# 0.3.0 is the first release of either package to ship R8 keep rules for its generated
70+
# messages, which is what lets proguard-rules.pro drop its own.
71+
ocp-client-protocol = "0.3.0"
72+
flipcash2-client-protocol = "0.3.0"
7173

7274
# The Android port is the ONLY libphonenumber this app depends on, deliberately. Google's
7375
# `com.googlecode` artifact used to sit alongside it; the two ship separate copies of the metadata,

0 commit comments

Comments
 (0)