Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose Slow build performance

I have been during the last couple of months playing and building a full app in compose. My project has grow, and now with Kodein and other libraries that work already with compose I'm starting to realize how slow sometimes the IDE build the app just to show a simple preview. It was great on a new project to change code, compile in 3-5s and see the result.

But now, it's taking between 30-60s even if the change in the code was minimal.

Is there any way presently to improve the building speed performance for the previews and compose projects?

like image 859
Francisco Durdin Garcia Avatar asked Dec 05 '25 03:12

Francisco Durdin Garcia


1 Answers

The Bad News

Under the hood, Compose works by performing annotation processing to turn your declarative @Compose functions into imperative rendering code. This annotation processing is done at build-time, which means it adds an extra step in the build process.

With XML and the View system, the UI wrangling is done at runtime. XML layouts are inflated at runtime, with no annotation processing necessary. This means that writing UI with Compose will always increase your build time compared to writing UI imperatively (with XML and the View system).

The Good News

Once you've accepted that you'll never reach the same build performance you had with the View system, you can start optimising. There are things you can do to take advantage of the gradle build cache, so that you only need to rebuild parts of the codebase since the last build. The official Gradle performance guide is here: https://docs.gradle.org/current/userguide/performance.html

A big potential gain is making use of gradle modules:

  • gradle can build independent modules in parallel
  • gradle can rebuild only the modules that have been updated

By splitting your codebase into modules, in particular extracting your Compose code to a dedicated UI module, you could see considerable build time improvements. I think this article explains this setup pretty well: https://proandroiddev.com/modular-architecture-for-faster-build-time-d58397cb7bfe

The Future

The Android Studio team seem to be focused on making Compose Previews render more quickly.

In the Artic Fox update, they added support for Live Edit of Literals. It works well in very specific circumstances.

In the Electric Eel update, they added Immediate Updates to Previews. Note that despite the name, updates are far from immediate. There are also many cases where a manual refresh of the Preview is still necessary.

In the Flamingo update, they added experimental support for Live Edit. Again, with a long list of exceptions.

Right now this tooling is not all there. But it is certainly getting better every update, and that makes me hopeful for the future!

like image 74
Luke Avatar answered Dec 07 '25 18:12

Luke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!