<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pratik Sahu on Medium]]></title>
        <description><![CDATA[Stories by Pratik Sahu on Medium]]></description>
        <link>https://medium.com/@pratiksahu184?source=rss-adb4aa10275a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RNUy9Fca32FM6Qov</url>
            <title>Stories by Pratik Sahu on Medium</title>
            <link>https://medium.com/@pratiksahu184?source=rss-adb4aa10275a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:32:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pratiksahu184/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scaling Android CI: From 44 → 10 minutes — A Deep Dive into Build Time Optimization and Best…]]></title>
            <link>https://medium.com/swiggy-bytes/scaling-android-ci-from-44-10-minutes-a-deep-dive-into-build-time-optimization-and-best-ff93aec82f05?source=rss-adb4aa10275a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff93aec82f05</guid>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[cache]]></category>
            <dc:creator><![CDATA[Pratik Sahu]]></dc:creator>
            <pubDate>Fri, 10 Jul 2026 05:14:33 GMT</pubDate>
            <atom:updated>2026-07-10T05:17:03.983Z</atom:updated>
            <content:encoded><![CDATA[<h3>Scaling Android CI: From 44 → 10 minutes — A Deep Dive into Build Time Optimization and Best Practices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nqahu2HQn3iwfPFiimGLQ.png" /></figure><p>Android monorepos get expensive and slow as they scale. We re-architected CI/CD caching, trimmed the Gradle graph, tuned the JVM, modernized the toolchain, and finally moved to Apple Silicon — plus specific configs and numbers you can replicate.</p><h3>Context and Baseline</h3><p>Our <strong>CI/CD</strong> pipeline started conventional: git clone → fetch npm and Android dependencies → execute <strong>Gradle</strong> build → notify; the build phase alone <strong>averaged ~35 minutes</strong> and repeatedly re-downloaded dependencies with no cache restore while configuration re-ran due to environment-driven invalidations. Each CI minute cost 2 credits.</p><p>After targeted optimizations, we cut total time to P90 = 11 minutes and P50 = 10 minutes, and reduced average credits per build from 55 to 43 (~20%).</p><p>At ~460 builds/month, we projected ~37% fewer credits and ~37% less wall-clock time, avoiding an imminent $22k/year tier-upgrade by staying on the current plan.</p><h3>What Was Holding Us Back</h3><ul><li><strong>Archive cache irrelevance</strong>: as many modules changed, CICD cache decayed fast and reuse dropped.</li><li><strong>Configuration invalidations</strong> from system properties and env inputs caused re-configuration even when tasks didn’t change.</li><li><strong>Dependency resolution overhead</strong>: Gradle probed multiple repositories for each coordinate, adding latency at our scale.</li><li><strong>Variant bloat</strong>: CI compiled non-required variants, inflating the task DAG by thousands of tasks.</li></ul><p><strong>Machine constraints</strong> created OOMs and noisy variability that masked true performance.</p><h3>Strategy Overview</h3><p>We focused on four compounding pillars:</p><ul><li><strong>Cache architecture</strong> with branch-aware keys, release/develop fallbacks, and a <strong>Gradle Remote Cache</strong> for task-level reuse.</li><li><strong>Build graph control</strong> to shrink the DAG: reduce inter-module coupling and enforce only required variants.</li><li><strong>Dependency resolution</strong> hardening via <strong>repository content filtering</strong> to avoid redundant lookups.</li><li><strong>Runtime tuning</strong>: right-size <strong>JVM heap/Metaspace</strong> for CI and disable work that helps locally but wastes time on ephemeral agents (e.g., configuration cache).</li></ul><h3>Optimization 1: Deterministic Caching with Branch-Scoped Keys</h3><p>We made caching <strong>branch-aware</strong> and OS/arch-aware, and cached more than artifacts: Android SDK components, project dependencies, transformed artifacts, <strong>NPM</strong> cache, and <strong>NDK</strong>.</p><p>Restore priority was: current branch → previous release → develop.</p><pre># Gradle restore (priority order)<br>{{ .OS }}-{{ .Arch }}-gradle-cache-v3-{{ getenv &quot;SWIGGY_CACHE_VARIANT&quot; }}-{{ getenv &quot;GIT_BRANCH&quot; }}<br>{{ .OS }}-{{ .Arch }}-gradle-cache-v3-{{ getenv &quot;SWIGGY_CACHE_VARIANT&quot; }}-release<br>{{ .OS }}-{{ .Arch }}-gradle-cache-v3-{{ getenv &quot;SWIGGY_CACHE_VARIANT&quot; }}-develop<br># Gradle save<br>{{ .OS }}-{{ .Arch }}-gradle-cache-v3-{{ getenv &quot;SWIGGY_CACHE_VARIANT&quot; }}-{{ getenv &quot;GIT_BRANCH&quot; }}<br># npm restore/save<br>{{ .OS }}-{{ .Arch }}-npm-cache-{{ checksum &quot;**/package-lock.json&quot; }}</pre><p>We normalized cache variants (release, releaseDebuggable) and gated cache saves to the default branch to reduce fragmentation and cost overhead:</p><pre># Decide cache variant and whether to save cache<br>cache_variant=&quot;prod&quot;<br>if [ &quot;$SWIGGY_APK_APP_VARIANT&quot; = &quot;release&quot; ] || [ &quot;$SWIGGY_APK_APP_VARIANT&quot; = &quot;benchmark&quot; ]; then<br>  cache_variant=&quot;release&quot;<br>elif [ &quot;$SWIGGY_APK_APP_VARIANT&quot; = &quot;releaseDebuggable&quot; ]; then<br>  cache_variant=&quot;releaseDebuggable&quot;<br>fi<br>envman add --key SWIGGY_CACHE_VARIANT --value &quot;$cache_variant&quot;<br><br>save_cache=false<br>default_branch=develop<br>if [ &quot;$GIT_BRANCH&quot; == &quot;$default_branch&quot; ]; then<br>  save_cache=true<br>fi<br>envman add --key PROJECT_DEFAULT_BRANCH --value &quot;$default_branch&quot;<br>envman add --key SWIGGY_SAVE_CACHE --value &quot;$save_cache&quot;</pre><p>Early lesson: continuously saving branch-level cache added overhead that often outweighed benefits on our credit-per-minute plan; using develop/release caches (refreshed automatically on back-merges via GitHub Actions) gave better ROI.</p><h4>Pricing plan tradeoff</h4><p>Under the credit-per-minute plan (2 credits/min), the 1–1.5 minutes (sometimes ~3 minutes) to save cache increased direct cost, so we avoided branch-level cache saves. Once we moved to a per-build plan, time overhead wasn’t billed linearly, and we started saving branch cache post-build.</p><h4>Post-Apple Silicon refresh</h4><p>After moving to Apple Silicon, we set the base branch cache as the primary restore, then save a branch-level cache after the first run so subsequent, same-branch builds consistently hit <strong>single-digit minutes</strong> when changes are localized.</p><h3>Optimization 2: Gradle Remote Cache (Module-Level Reuse)</h3><p>CICD archive cache staled quickly as more modules changed, so we piloted a <strong>Gradle Remote Cache</strong> on a small <strong>EC2</strong> (Linux, 8GB RAM, 256GB SSD) serving GET/PUT under /cache.</p><p>Results from the POC:</p><ul><li>Incremental builds: cache hit is now P50 = 44% and P90 = 56% (latest),</li></ul><p>This raised incremental hit rates and stabilized day-to-day developer builds.</p><h3>Optimization 3: Build Only What Matters (Variants + DAG)</h3><p>We enforced building only required release variants in CI, <strong>cutting total Gradle tasks by ~26% (3399 → 2745)</strong>.</p><p>We also reduced inter-module coupling across 100+ modules to widen parallelism and shorten the critical path — an ongoing effort with tangible impact.</p><h3>Optimization 4: Repository Content Filtering</h3><p>On clean builds, Gradle’s multi-repo probing added up. We introduced <a href="https://docs.gradle.org/current/userguide/filtering_repository_content.html"><strong>repository content filtering</strong></a> so Gradle fetched coordinates from the correct repo without trial-and-error, reducing resolver latency for our large graph.</p><h3>Optimization 5: Right-Size the JVM for CI</h3><p>We ran controlled trials and converged on <strong>Heap = 16GB</strong> and <strong>Metaspace = 12GB</strong> for 32GB runners, balancing GC frequency and pause time while avoiding OOMs.</p><p>Representatively, under the develop/release cache plan, end-to-end times routinely landed around ~20–22 minutes when cache hit was healthy.</p><p>We also disabled <strong>configuration cache</strong> in CI after build scans showed ~30 seconds spent saving a cache that’s not reused in ephemeral CI — useful locally, wasteful in pipelines.</p><h3>Optimization 6: Machines That Don’t Fight You</h3><p>We moved from Ubuntu 22.04 L to XL to eliminate OOMs; Bitrise’s SOC update (Google → AMD) improved times, and M1 Max trials reached ~15 minutes with availability caveats at the time.</p><p>We’ve since moved critical workflows to Apple Silicon (M4 Pro, 54GB), which tightened variance and removed memory headroom issues seen on earlier x86 profiles.</p><h3>Toolchain Modernization</h3><p>We bumped <strong>Kotlin</strong>, <strong>AGP 8.10.1</strong>, and the <strong>Gradle wrapper 8.11.1</strong>. Combined with the refreshed caching approach on Apple Silicon, this pushed subsequent, small/localized builds into single-digit minutes.</p><h3>Results</h3><p><strong>Baseline vs improvements:</strong></p><ul><li><strong>Before optimizations on x86</strong>: P90 ≈ 44m, P50 ≈ 35m.</li><li><strong>After pipeline optimizations on x86</strong>: P90 ≈ 26m, P50 ≈ 23m; average credits per build 55 → 43 (~20% lower); ~37% monthly reductions in both credits and minutes; avoided a $22k/year tier-upgrade.</li><li><strong>After Apple Silicon</strong> (M4 Pro, 54GB) and cache/toolchain refresh: P90 = 11m, P50 = 10m.</li></ul><p><strong>Additional visible effects:</strong></p><ul><li><strong>“Time to start build”</strong> dropped from ~4–5 minutes to 30–90 seconds depending on cache source.</li><li>In a comparable live window after rollout, we saved ~5800 credits (~45%).</li></ul><h3>What We’d Do Again (Best Practices You Can Lift)</h3><ul><li><strong>Use branch-aware, tiered cache keys</strong> and avoid saving branch caches on every run under per-minute billing; refresh authoritative develop/release caches automatically on back-merges.</li><li><strong>Adopt a Gradle Remote Cache</strong> for large modular repos to stabilize incremental builds and raise hit rates.</li><li><strong>Trim the DAG ruthlessly</strong>: enforce required variants only; stub or disable non-essential modules in CI to cut tasks.</li><li><strong>Constrain dependency lookups</strong> with repository content filtering to reduce resolver overhead.</li><li><strong>Tune the JVM to the runner</strong> and validate with CI trials; target predictable GC over edge-of-OOM settings.</li></ul><p><strong>Right-size machines</strong> and prefer Apple Silicon for Kotlin/AGP-heavy builds where available to compress build times.</p><h3>Acknowledgements</h3><p>I am Pratik Sahu from the Android Mobile team at Swiggy and I’d like to thank <a href="https://medium.com/u/723d70adf627">Sambuddha Dhar</a>, <a href="https://medium.com/u/1bf9bdb89775">Raj Gohil</a> and <a href="https://medium.com/u/400467f4ffab">Tushar Tayal</a>. This milestone wouldn’t have been possible without their constant help and support</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff93aec82f05" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swiggy-bytes/scaling-android-ci-from-44-10-minutes-a-deep-dive-into-build-time-optimization-and-best-ff93aec82f05">Scaling Android CI: From 44 → 10 minutes — A Deep Dive into Build Time Optimization and Best…</a> was originally published in <a href="https://medium.com/swiggy-bytes">Swiggy Bytes — Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>