Skip to content
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

Update to Hilt 2.48 and use the KSP version #933

Merged
merged 1 commit into from
Nov 12, 2023
Merged

Conversation

danysantiago
Copy link
Contributor

  • Moved protobuf to separate module to avoid having to wire KSP's Plugin with the Protobuf Plugin.
  • @Binds function cannot be an extension function.

@tunjid
Copy link
Contributor

tunjid commented Aug 30, 2023

Thanks so much @danysantiago! Why can't @Binds be an extension function?

@manuelvicnt
Copy link
Contributor

@tunjid the rationale is in the release notes

@dturner
Copy link
Collaborator

dturner commented Aug 30, 2023

Please fix the spotless issues by running:

./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache

@SimonMarquis
Copy link
Contributor

SimonMarquis commented Aug 30, 2023

😢 The current version of Hilt KSP (still experimental) triggers a lot of OOMs on CI...

e: java.lang.OutOfMemoryError: Metaspace

During my tests (compilation + unit tests):

  • The Kotlin compiler daemon used up to 220m of metaspace
  • The Gradle daemon used up to 330m of metaspace

It seems like the current default is set by Gradle to 384m.
Should we try to increase it on CI? (we are using 1g by default on local builds)

@danysantiago
Copy link
Contributor Author

It seems like the current default is set by Gradle to 384m. Should we try to increase it on CI? (we are using 1g by default on local builds)

Oh noes! 😢

It seems the project is already configured with 1g: https://github.com/android/nowinandroid/blob/main/gradle.properties#L11. Is this config not the same as the one in CI?

@SimonMarquis
Copy link
Contributor

Oops, you're right, I was thinking of another project configuration.
We are indeed using 1g of metaspace.

The currently configured max heap space is '4 GiB' and the configured max metaspace is '1 GiB'.

kotlin.compiler.execution.strategy=in-process could be part of the issue, if both daemon adds up to this limit 🤔

@SimonMarquis
Copy link
Contributor

OOF...

image

I confirm that ksp* tasks are responsible for these spikes in metaspace usage.
Removing kotlin.compiler.execution.strategy=in-process make these spikes less noticeable, even in the Kotlin compiler daemon which remains ~250m.

This Kotlin compiler setting was introduced in the first PR of this project #1, but I'm not sure why.

@lihenggui
Copy link
Contributor

Looks like Google is aware of this issue and mentioned in the release note:

Also note that Dagger’s KSP processors are still in the alpha stage. So far we’ve focused mainly on trying to ensure correctness rather than optimize performance. Please apply due diligence when enabling ksp and report any bugs or performance issues at https://github.com/google/dagger/issues. The current list of known issues can be found here.

Shall we report an issue to them?

@manuelvicnt
Copy link
Contributor

While running locally, I could see an increase in memory metadata usage but it didn't go over 1GB.

KAPT

kapt

KSP

ksp

@SimonMarquis
Copy link
Contributor

@manuelvicnt did you get these results with kotlin.compiler.execution.strategy=in-process?

@android android deleted a comment from abalros2 Aug 31, 2023
@manuelvicnt
Copy link
Contributor

@SimonMarquis Yeah, using the current state of this PR

@danysantiago
Copy link
Contributor Author

I've commented kotlin.compiler.execution.strategy=in-process for now to avoid the OOMs in due to increased metaspace usage. There has been reports that the spikes are due to changes in Kotlin 1.9.0 and not necessarily KSP + Hilt, the team is investigating internally but for now feel free to their hold on this PR or merge without the in-process if it works.

Copy link
Contributor

@JoseAlcerreca JoseAlcerreca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

holding until we investigate

@jdkoren
Copy link
Contributor

jdkoren commented Oct 20, 2023

I'd like to look into this, what is the tool being used in this comment? #933 (comment)

@jdkoren
Copy link
Contributor

jdkoren commented Oct 30, 2023

@SimonMarquis which tool are you using in this comment?

@SimonMarquis
Copy link
Contributor

This is VisualVM

@SimonMarquis
Copy link
Contributor

FWIW:

the current implementation of the in-process strategy is suboptimal, however we have plans to improve it

https://kotlinlang.slack.com/archives/C19FD9681/p1696201557559239?thread_ts=1695989901.167479&cid=C19FD9681

@dturner
Copy link
Collaborator

dturner commented Nov 9, 2023

@SimonMarquis Thanks for sharing that thread on KotlinLang. Seems like we shouldn't be using in-process anyway and it's a hangover from the original project setup.

Full context on why using in-process is suboptimal from the same thread

Currently it’s creating a new class loader for each compilation task, that may cause higher memory consumption and much slower compilation because JVM shall load classes and perform JIT compilation for the compiler classes almost from scratch. So I won’t recommend using it for the main build as I consider it consists of at least a few modules. However, it’s ok to use it for buildSrc or the single build-logic module. It shouldn’t cause any problems in this case if you’re ok with not having incremental compilation for that module.

@ffgiraldez
Copy link

I'm still having issues with hilt 1.1.0 and ksp due to OOM

* Moved protobuf to separate module to avoid having to wire KSP's Plugin with the Protobuf Plugin.
* `@Binds` function cannot be an extension function.
* Commented `kotlin.compiler.execution.strategy=in-process` in CI to circumvent OOMs due to increased metaspace usage.
@dturner dturner merged commit f3b2655 into android:main Nov 12, 2023
4 checks passed
@dturner
Copy link
Collaborator

dturner commented Nov 12, 2023

@ffgiraldez Please could you share more details of your project and reproduction steps for the OOM by filing a new issue here: https://github.com/google/dagger/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants