[FR]: Faster build speed with Gradle properties + jemalloc

Open
#1,510 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, kotlin

Research direction

Start by reviewing the performance testing and changes in pull request #1492, then compare the proposed JVM, jemalloc, and Gradle property settings for local Android builds and GitHub CI. Done means the settings are agreed, documented in the project configuration, and their build-speed and memory effects are measured.

Written by the indexing model from the issue text.

Description

enhancement
Is there an existing issue for this?
  • I have searched the existing issues
Describe the problem

I was talking about the settings used in this project with @liutikas and some others. It was speculated that it was possible to reduce the JVM heap size the project uses and also attain a faster build speed.

Describe the solution

I propose we do this by:

  • Using jemalloc as a malloc replacement - most projects get about 10% memory freed up, though no build speed impact
  • Use G1GC - I've seen this work better for Android projects that use JDK 19 or later, or if they're simply having some memory contention/pressure issues with running the project on resource constrained machines.
  • SoftRefLRUPolicy - This is defaulted to 1000 which at current settings would take almost 2 hours to release any soft ref
  • ReservedCodeCacheSize - Increasing this from the default allows the project to preallocate the codecache and not have to spend time growing it during a build
  • MetaspaceSize - From my research about Metaspace, Android Gradle builds benefit the most when MaxMetaspace is allowed to be unlimited (the JVM default) and MetaspaceSize set to 512MB or 1GB instead of the default 20MB. This is because MaxMetaspace is a constraint on both Metapsace and ClassPointers, the latter of which defaults to 1GB.
  • Min & max heap - Experimentation required to see what the optimal heap size for the project would be for both local development and GitHub CI.
Additional context

I already did the performance testing and changes, I'm just filling this out so the change can be considered and reviewed.

Code of Conduct
  • I agree to follow this project's Code of Conduct
Dominant language
Kotlin
Stars
22.1k
Forks
4.7k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/nowinandroid

All issues in android/nowinandroid

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.