-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Disable ProGuard's optimizations by default #3392
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -637,3 +637,14 @@ compose.desktop { | |
} | ||
} | ||
``` | ||
|
||
ProGuard's optimization is disabled by default since Compose 1.5. To enable it, set the following property via Gradle DSL: | ||
``` | ||
compose.desktop { | ||
application { | ||
buildTypes.release.proguard { | ||
optimize.set(true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will users encounter If yes, we should add a rule to the default rules There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @igordmn It is not possible to "turn it off" optimizations for a single class. The problem is not that the class is removed or renamed, but that it is rewritten in a way, which violates the JVM bytecode verification. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested on Compose 1.4.1, Windows
benchmark, startup + single frame, LazyGrid, median, 10-15 tries:
When we apply optimizations - no significant improvements when we render frames, but there are some improvement in the startup time. So, it is preferable to keep optimizations working - this PR fixes this particular issue. Also I created a task for the future - run all Compose tests after ProGuard optimizations. As for disabling optimizations by default - it is debatable, let's just keep them enabled until there will be a strong argument against it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, let's enable optmizations again but keep it in Gradle DSL |
||
} | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
release
builds usually should be optimized.Can we:
I wouldn't make this change only to speed up release and simplify the release process.
As an example, Android builds enable optimizations in the release build, and there is the rule that each third-party library should contain a valid ProGuard rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there is no such rule for desktop. With lots of external libraries it is often a PITA to get all the ProGuard rules right just in order to be able to do a release build. Maybe one should not carry over all Android habbits to the rest of the world.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is useful rule, otherwise we have a situation as you described. We have this situation though, becase indeed - there is no rule for JVM libraries.
But then, it is not only about optimization, ProGuard itself becomes useless. Every library can have some classes that require specific ProGuard rules (for example, if it uses reflection). We either should disable ProGuard completely, or provide a configuration that works for templates and popular libraries.
Not sure that disabling is a good idea, because there won't be any point in Release builds (ProGuard is the only difference at the moment)
Regarding the
androidx/compose/animation/core/AnimationSpecKt.estimateAnimationDurationMillis
issue - it is Compose class, so it should be fixed in Compose ProGuard rulesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a dillemma. I have to admit that I do not have an Android background but I have been using JavaFX with GraalVM/native-image which conceptually has a similar problem and so I am wondering whether you ever considered something like the native-image agent (https://www.graalvm.org/22.0/reference-manual/native-image/Agent/) which I found to be very helpful and easier to use than guessing ProGuard rules for libraries which are not your own. Would some kind of a bridge between the agents output and ProGuard be possible? Just thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
native-image/Agent
looks interestingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both cases most likely no.
I don't see any way to exclude just one class from optimization.
Also, simply forcing classloading does not trigger the verification error, which is described in the issue.
Also, I'm really not sure, if PG optimizations are actually beneficial with Hotspot. The desktop JVM is much better at optimizing code than mobile. Our primary motivation for supporting PG was to enable minification, not making bytecode faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After having a closer look at https://www.guardsquare.com/manual/configuration/optimizations I am a bit shocked to realize what PG is actually trying to do with my code by default. This really looks like fishing for trouble to me where all I really want is a reliable build combined with some reasonable code reduction. Packaging your app with the most recent JVM is probably more beneficial and safer than applying all this bit fiddling.