Minimize Kotlin Standard library Option #4948
Open
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.
Add an option for minimizing the imports from Kotlin package
kotlin.**
for Compose Desktop Gradle Plugin without breaking changesI created a new example using kmp.jetbrains.com and tested the local changes with the default example:
Before minimizing Kotlin standard library:
After:
The provided screenshots are on macOS DMG using
packageReleaseDeb
and the difference will be different based on the method and the operating system:packageReleaseDeb
packageReleaseUberJarForCurrentOS
createReleaseDistributable
You should save more depending on the imports. In this example, we don't use much, and it's mostly from the libraries.
I have removed
will be included if
minimizeKotlinStandardLibrary
is false, which is the default. If you're interested in this PR, before merging it, we should make sure of the following:minimizeKotlinStandardLibrary
should be renamed for some reasons, one of them, could indicate it will be minimized, and only the used/required imports will be included, which might be not the case as it currently only avoids including-keep class kotlin.** { *; }
in the rules, if we will stick to this behavior then the name could be changed to something else, likekeepEntireKotlinStdLib
orretainFullKotlinStdLib
or something similar to indicate rules will be required depending on the usage, and will add a swcond option likeincludeDefaultKotlinStdLibRules
orincludeCommonKotlinStdLibRules
which will include some common rules such as:See Progaurd Kotlin Manual for more details.
Another option is to provide some common/required rules for the Kotlin standard library and provide a function or option to disable this behavior.
I suggest keeping standard library or std lib or something similar in the name as this will not take
kotlinx
packages into account to make it clear and understandable for the developer, or we could stick to only having one option (e.g,minimizeKotlinStandardLibrary
), and make it nullable boolean if it'snull
, then it will ignore the call or iftrue
, will use-keep class kotlin.** { *; }
, or iffalse
then either ignore the call (in that case the value should not accept null as value) or provide some common/default rulesLog
The reason I didn't handle this as I don't have enough information about the approach that you prefer to use as discussed above, and I don't have any Compose Desktop projects, the examples provided in this repository use the libraries and plugins of this repository from maven central instead of the ones locally in the machine.
This change is only tested on the Jetbrians example, and it seems to work as expected.
4.49% may not sound very significant, however, it's one step toward minimizing the bundle size and it's optional (disabled by default), I haven't looked into the source code although it seems that Skia is quite big, to save more, we need rules to explicitly keep the classes, methods when necessary, the current setup will exclude Skia from minimization
compose-multiplatform/gradle-plugins/compose/src/main/resources/default-compose-desktop-rules.pro
Lines 2 to 3 in 8432577