Status Update
Comments
bi...@google.com <bi...@google.com> #2
With the new API(withVariantReselection
), We suspect it is not GC ed after the resolution. GC seems to do a better job for artifactResolutionQuery
(detached configuration
(
bi...@google.com <bi...@google.com> #3
I managed to produce some consistent numbers and here is what I did.
To get some numbers of the old way(artifactResolutionQuery
& detachedConfiguration
) of resolving javadoc/source/samples
- open the android-extra-large-benchmark project(the 200 module version) with dev versions of AGP and Android Studio, set up the studio flag
GRADLE_HEAP_ANALYSIS_OUTPUT_DIRECTORY
to the path of hprof output directory - sync the project and close android studio
- reopen android studio, kill all daemon with
./gradlew --stop
- click the sync button
- open the two hprof files(one before sync and one after sync)
I got 458MB for the retained size of strong reachable before sync and 912MB after sync. Repeat step 2-5 again and I got 463MB before sync and 917 after sync.
To get data of using the new way(withVariantReselection
) of resolving javadoc/source/samples
- enable the new feature with AGP flag(
android.experimental.additionalArtifactsInModel=true
) and comment out the old resolution code for building theAdditionalClassifierArtifactsModelBuilder
- re-build android studio
- open the same benchmark project and repeart step 2-5
I got 458MB before sync and 948MB after sync for the first iteration, and 458MB before sync vs 948 after sync for the second iteration.
So basically we are able to reproduce the memory regression 910MB->948MB
Ivan, Ahmet, does the above approach sound good?
A few things worth mentioning
- re-open studio is to make sure no studio cache for javadoc/source is used
- As we capture gradle daemon memory before and after sync, killing daemon before the sync seems to be a good way to have consistent result
- With 1 and 2, it is safe to say only gradle persistent cache could be used for javadoc/source/sample resolution.
To allow Gradle folks to reproduce like the way I did, I think we need to land Bradley's CL so they can disable the old approach.
bi...@google.com <bi...@google.com> #4
The initial motivation of switching to this new API is 1) support resolving javadoc/source/sample published with multiple variants(e.g. debug/release) 2) to have a persistent cache for javadoc/source/sample instead of relying on studio cache. The second point is actually addressed by Gradle regardless of using this API or not. Although artifactResolutionQuery
could not let us add attributes, but in theory detachedConfiguration
allows that.
So my question to Grade folks is, do you think we could reduce the memory usage when using withVariantReselection
api? If not, what is the advantage of using withVariantReselection
over detachedConfiguration
?
bi...@google.com <bi...@google.com> #5
Some updates: as Bradley's change is checked in, Gradle team should be able to reproduce and get some numbers without making changes to source code.
ga...@google.com <ga...@google.com> #6
Can you please file an internal bug and use Bugjuggler to block on the Gradle issue?
bi...@google.com <bi...@google.com> #7
I don't think there is an Gradle issue filed for that. I need to sync with Ahmet to capture the conversations between AGP and Gradle.
vm...@google.com <vm...@google.com> #8
Recently I was investigating a memory regression artifactview
on Gradle 8.4-rc-2
that can be appreciated on the bellow results:
- Gradle 8.3:
- Gradle 8.4:
android.experimental.additionalArtifactsInModel=true
(~11.15 GB sync memory heap)android.experimental.additionalArtifactsInModel=false
(~11.15 GB sync memory heap)
Those tests have been done using our gradle 8.4-rc-2
bi...@google.com <bi...@google.com> #9
Thanks Madalin for the help and sorry for the late reply. This week, I am going to test it out using the step mentioned above and share the result.
bi...@google.com <bi...@google.com> #10
Running bazel test //tools/adt/idea/sync-memory-tests:intellij.android.sync-memory-tests_tests__Benchmark2000Memory --config=remote
with latest AGP and Gradle 8.4
Current set up:
android.experimental.additionalArtifactsInModel=false
and GradleExperimentalSettings#USE_MULTI_VARIANT_EXTRA_ARTIFACTS=false
2000Modules_Sync_Finished retained heap size about 8.1G
Switch to new pipeline:
android.experimental.additionalArtifactsInModel=true
and GradleExperimentalSettings#USE_MULTI_VARIANT_EXTRA_ARTIFACTS=true
(changing default value of those two properties)
2000Modules_Sync_Finished retained heap size about 8.7G
Therefore, I don't think the regression is fixed on Gradle side.
Note GradleExperimentalSettings#USE_MULTI_VARIANT_EXTRA_ARTIFACTS
controls the behavior on the sync side, setting it to true means we would just use the resolved artifacts provided from the model instead of doing fetching from the sync side. However, I notice setting it to false doesn't increase memory too much on top of setting android.experimental.additionalArtifactsInModel
to true.
Based on the discussion in this slack channel
And also they mentioned "We are currently discussing ways to get gradle to release resolved dependency graphs by allowing users to declare dependency resolution as inputs, therefore allowing gradle to know if a given configurations graph is no longer necessary. Though this is still in the works"
I think the memory increase comes from not releasing resolved dependency graph when using withVariantReselection
.(This may not apply to previous AGP version when we don't use detachedConfiguration)
The ticket filed to Gradle
li...@bytedance.com <li...@bytedance.com> #11
bi...@google.com <bi...@google.com> #12
As suggested by Gradle folks, I collect some CPU and memory data using Gradle 8.12 with the feature turned on. I checked with Ahmet and the result is promising. We plan to turn on the multi variant javadoc/source support feature by default after Gradle 8.12 upgrade and carefully monitor the performance impact.
ad...@decathlon.com <ad...@decathlon.com> #13
We already have a library with multi modules and multi variant, but we are not able to see sources on Android Studio for these modules.
Description