feat(r8): ship keep rules for the generated messages - #5
Merged
Conversation
protobuf-javalite ships no keep rules of its own, so every Android consumer has to
write one. code-android-app carried `-keep class * extends GeneratedMessageLite { *; }`
and the matching $Builder rule; together they pinned 29,633 items — 94% of that app's
entire keep radius — and blocked R8 from optimizing 24,909 methods, 81% of every method
it was forbidden to touch. 150 of the 461 message classes and 1,215 of the 3,800 fields
those rules covered come from this package.
Almost all of that was unnecessary. javalite resolves fields reflectively — the schema
built from newMessageInfo looks up Field objects against the generated `<name>_` fields —
but builders and message methods are reached from ordinary call sites, so R8 traces them
without help. tink-android already ships exactly this narrower form for its own shaded
copy of javalite.
The rule is deliberately not scoped to com.codeinc.opencode.gen.**. The well-known types come from
protobuf-javalite itself, and other dependencies ship generated messages with no rules of
their own; a scoped rule would leave both broken under R8 full mode.
Owning the rule here also means an app that adds this dependency gets working protobuf
under minification without knowing any of the above.
* origin/main: chore(contract): sync ocp protos to ea6418c5 and add a changelog (#4)
publish.yml reads the section matching the version it is publishing, so 0.3.0 could not release without one. The entry leads with what is not in it — no contract change, the lock file unmoved, the generated Swift untouched — because a version number moving usually means the opposite, and a Swift consumer has no reason to take this one. Also points the README install snippets at 0.3.0; they still read 0.1.0.
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
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.
protobuf-javalite ships no keep rules of its own, so every Android consumer has to write
one.
code-android-appcarried-keep class * extends GeneratedMessageLite { *; }and thematching
$Builderrule. Between them they pinned 29,633 items — 94% of that app's entirekeep radius — and blocked R8 from optimizing 24,909 methods, 81% of every method it was
forbidden to touch. 150 of the 461 message classes and 1,215 of the 3,800 fields those rules
covered come from this package.
Almost none of that was needed. javalite resolves fields reflectively: the schema built from
newMessageInfolooks upFieldobjects against the generated<name>_fields. Builders andmessage methods are reached from ordinary call sites, so R8 traces them without a rule.
tink-android already ships exactly this narrower form for its own shaded copy of javalite.
-keepclassmembersdoes not keep the class, so a message type nothing references is stillremoved entirely — the rule only applies to messages that survive on their own merit.
Why it is not scoped to
com.codeinc.opencode.gen.**The well-known types (
Any,Timestamp,Duration,Struct) come from protobuf-javaliteitself, and other dependencies ship generated messages with no rules of their own —
firebase-perfis one. A rule scoped to the generated package would leave both broken underR8 full mode. Measured against the app, the rule's radius spans four artifacts:
Both contract packages ship identical rule text and R8 collapses them into a single entry, so
the duplication costs nothing and either artifact alone is sufficient.
Effect on the consumer
Built through
protoLocalRoot, with the app's own protobuf rules removed:Owning the rule here also means an app that adds this dependency gets working protobuf under
minification without knowing any of the above.
Consumer side: code-payments/code-android-app#1370
Release
Ships as
0.3.0. Mergedmainin and added the## 0.3.0changelog section —publish.ymluses it as the release notes and refuses to publish a version without one — and pointed the
README install snippets at it. No contract change, so the Swift tag carries nothing new.