Repository navigation
Cache Kotlin/Native library caches in iOS KMP PR checks - #125
Merged
Merged
Conversation
Debug framework links build a native cache for every library dependency in ~/.konan/.../klib/cache. Self-hosted runners start from a fresh VM, so every PR check rebuilt them: ~4 of the ~4m40s link in uniapp-kmp (Compose Multiplatform), against 28s with the caches present. The new opt-in `kotlin_native_cache` input caches only those library caches (~340 MB), keyed on libs.versions.toml without a restore-keys fallback so outdated library versions do not accumulate. The compiler distribution and LLVM (~16s to download) are left out: restoring them would cost about as much as it saves.
matejsemancik
marked this pull request as draft
October 7, 2026 12:55
matejsemancik
marked this pull request as ready for review
October 7, 2026 13:41
matejsemancik
marked this pull request as draft
October 7, 2026 13:47
matejsemancik
marked this pull request as ready for review
October 7, 2026 14:07
ssestak
approved these changes
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Debug framework links build a native cache for every library dependency in
~/.konan/kotlin-native-prebuilt-*/klib/cache. KMP projects run on self-hosted runners that start from a fresh VM, so every PR check rebuilds all of them inside the link task.Measured on a project that renders Compose Multiplatform on iOS (126 library dependencies,
linkDebugFrameworkIosSimulatorArm64only):disableNativeCache)The Kotlin docs recommend preserving
~/.konanbetween CI builds: Preserve downloaded and cached components between builds.What
ios-kmp-selfhosted-testgets akotlin_native_cacheinput, enabled by default, so every KMP project gets the cache once it bumps to the release with this change. It adds anactions/cache@v6step beforeBuild KMP Package:~/.konan/kotlin-native-prebuilt-*/klib/cache/*-user*, only the library caches built during the link (~340 MB for the measured project's simulator slice). The compiler distribution and LLVM are left out: downloading them takes ~16 s, and restoring ~1.3 GB more would cost about as much.libs.versions.toml, with norestore-keysfallback. Library caches live in per-version folders, so a partial restore would carry outdated versions into every new cache.actions/cachesaves at the end of the job, only on a key miss and only when the job succeeds.Release builds don't use these caches, so nightly and release workflows are unaffected.
Impact on projects: no changes needed beyond the version bump. Each project stores one cache entry per
libs.versions.tomlstate (a few hundred MB, depending on its dependencies) in its 10 GB repo cache budget. A project can opt out withkotlin_native_cache: false.Sharing the cache across PRs
A cache saved in a PR run is only visible to later runs of that PR. To let every PR restore it, projects can also run their check on
pushtodevelop(push: branches: [ develop ], with the concurrency group usinggithub.head_ref || github.ref). Change detection (dorny/paths-filter), the iOS Fastlanetestlane and the Android Danger step all handle push events.Testing
Planned on a consumer project's PR pointed at this branch (no input needed now that it's on by default): the first run should miss and save, and a second run after a UI-only change should restore the cache and link in ~30–40 s.