Kill Kotlin daemon before R8 to reduce peak memory on release builds#356
Merged
Kill Kotlin daemon before R8 to reduce peak memory on release builds#356
Conversation
Implements the technique from https://dev.to/cdsap/what-happens-when-you-kill-the-kotlin-daemon-before-r8-el7 directly in the build script rather than via the R8Booster plugin, which has a bug where it applies task wiring to all variants (not just release), causing a circular task dependency when running debug unit tests. Scoping finalizedBy/dependsOn to release Kotlin compile and minify tasks avoids the cycle while preserving the ~14-15% peak memory savings from releasing the Kotlin daemon process before R8 starts. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Diffuse output: |
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.
Summary
Details
The R8Booster plugin (
io.github.cdsap.r8booster) has a bug: it appliesfinalizedBy(killKotlinCompileDaemon)to allKotlinCompiletasks project-wide (including test tasks), anddependsOn(killKotlinCompileDaemon)to allJavaCompiletasks. This creates a circular dependency when running debug unit tests:The manual implementation scopes the wiring to release tasks only:
tasks.withType<KotlinCompile>().configureEachwith a name guard for release (no test) taskstasks.matching { startsWith("minify") && endsWith("WithR8") }instead oftasks.named()since AGP 9.x registers these tasks lazilyTest Plan
assembleRelease—killKotlinCompileDaemonruns aftercompileReleaseKotlin, beforeminifyReleaseWithR8testDebugUnitTest— no circular dependency errorspotlessCheck— formatting passestasks— configuration resolves cleanly🤖 Generated with Claude Code