kotlin-tooling-native-build-performance
Diagnoses and fixes slow Kotlin/Native compilation and linking in Kotlin Multiplatform projects that target iOS. Use when the user reports slow iOS or shared-framework builds, long linkDebug*/linkRelease* or XCFramework tasks, cold CI builds that re-download the Kotlin/Native toolchain, KSP or other
- 0
- Installs
- —
- Rating
- —
- Success rate
- 7
- Files scanned
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 df2356261273d263… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
Kotlin/Native Build Performance
Turn "the iOS build is slow" into a measured diagnosis and a small set of safe fixes. Two rules apply throughout:
- Never trade away required release behavior. A faster local loop must not change what CI publishes.
- Measure before and after with the same command and the same build state. An unmeasured fix is a guess.
Step 0: Classify the Slow Scenario
Establish four facts before editing anything: where (local or CI), what (debug feedback loop or release/distribution artifact), state (first build, clean, warm, or no-op), and phase (which tasks dominate the log). Then match the dominant symptom:
| Symptom in the build log | Likely cause | Read |
|---|---|---|
linkRelease* or *ReleaseXCFramework tasks in a local development loop | Building distribution artifacts for development | artifacts-and-targets |
| Kotlin/Native compiler distribution downloaded on every CI run | ~/.konan not preserved between runs | caching-and-gradle |
| Long pause before the first task starts | Configuration phase, no configuration cache | caching-and-gradle |
| All iOS targets build when only one simulator is needed | Broad task (build, assemble, assemble*XCFramework) or unused targets | artifacts-and-targets |
ksp* tasks ahead of compileKotlinIos* | Generated-code work on the native path | exports-and-generated-code |
| Small source edit recompiles and relinks everything | Compiler caches disabled, or missing incrementality | caching-and-gradle, experimental |
Machine overloaded while several link* tasks run at once | Parallel native linking | caching-and-gradle, worker-limit caveat |
Step 1: Audit and Measure
-
Run the static audit from the project root:
scripts/audit-native-build.sh /path/to/projectIt is read-only and prints
file:linefindings (disabled caches, broad local tasks,transitiveExport, broad KSP configuration, missing CI.konancache), each pointing at the reference file with the fix. Findings are leads, not verdicts — confirm each against project policy. -
Find the command the user actually waits for: a script, a CI step, or the Gradle invocation inside an Xcode build phase. Optimize that command, not a task you picked yourself.
-
Run it twice when practical. The first build downloads Kotlin/Native components and fills caches; only the second and later runs are representative. Attribute time per task before blaming the compiler:
kotlin.build.report.output=file # writes build/reports/kotlin-build/Gradle's
--scanor--profilework too. -
If you cannot run the build (no macOS host, no Xcode), analyze logs, build scans, or checked-in metrics instead — and state explicitly that the conclusion is static.
Step 2: Fix in Safe Order
Apply fixes one at a time, re-measuring as you go:
- Restore healthy defaults — remove cache/daemon workarounds, enable
Gradle build and configuration caches, keep
~/.konanwarm in CI, update Kotlin: references/caching-and-gradle.md - Build only what the feedback loop needs — one specific task per loop, correct integration method, justified target matrix: references/artifacts-and-targets.md
- Cut export and generated-code cost — drop
transitiveExport, narrowexport(...), scope KSP work to the native compilations that need it: references/exports-and-generated-code.md - Experimental switches last, with the user's agreement: references/experimental.md
Worked Example
A developer on an Apple Silicon Mac complains that "every shared-module
change costs 12 minutes". Their loop runs ./gradlew :shared:assembleXCFramework.
A build scan of the second (warm) run shows:
:shared:linkReleaseFrameworkIosArm64 348s
:shared:linkReleaseFrameworkIosX64 341s
:shared:compileKotlinIosX64 96s
:shared:linkDebugFrameworkIosSimulatorArm64 41s
:shared:compileKotlinIosSimulatorArm64 38s
configuration phase 64s
Reasoning chain:
- The loop is local + debug + warm, but ~690s goes to
linkRelease*— release linking is an order of magnitude slower than debug and only CI needs it. Replace the local command with:shared:linkDebugFrameworkIosSimulatorArm64(or the Xcode embed task if Xcode drives the build). (artifacts-and-targets) - All
iosX64work serves Intel simulators; ask whether the team still supports them before removing the target. (artifacts-and-targets) - 64s of configuration on every run disappears behind
org.gradle.configuration-cache=trueonce trialed. (caching-and-gradle) - Expected loop after the change: ~40s compile + ~40s link on warm builds — confirm by re-running the new command twice and comparing.
- CI keeps
assembleXCFrameworkuntouched; note that explicitly in the report.
Verify
- Re-run the exact baseline command; compare warm build against warm build, not warm against cold.
- Second run with the configuration cache reports it is being reused.
- The local development log no longer contains
linkRelease*,*ReleaseXCFramework, or removed generator tasks. - CI still produces every required release artifact, unchanged.
- Tests pass and the app still runs from Xcode.
-
scripts/audit-native-build.shreports no findings you have not consciously accepted and documented.
Report Your Changes
Close with a short performance note:
- The slow scenario (local/CI, debug/release, cold/warm) and the measured evidence — or a statement that the analysis was static.
- Each change, and why it is safe for release behavior.
- The before/after commands the user can run to confirm the win.
- Remaining tradeoffs: experimental flags enabled, targets removed under a policy assumption, worker limits, or generated-code work deferred.
- Links to the relevant official documentation below.
Official Documentation
| Topic | Link |
|---|---|
| Improving Kotlin/Native compilation time | https://kotlinlang.org/docs/native-improving-compilation-time.html |
| Kotlin Gradle plugin compilation and caches | https://kotlinlang.org/docs/gradle-compilation-and-caches.html |
| iOS integration methods | https://kotlinlang.org/docs/multiplatform-ios-integration-overview.html |
| Direct integration with Xcode | https://kotlinlang.org/docs/multiplatform/multiplatform-direct-integration.html |
| Building final native binaries and XCFrameworks | https://kotlinlang.org/docs/multiplatform/multiplatform-build-native-binaries.html |
| Kotlin/Native binary options | https://kotlinlang.org/docs/native-binary-options.html |
| KSP with Kotlin Multiplatform | https://kotlinlang.org/docs/ksp-multiplatform.html |
Files
7- SKILL.md
948fcecafa7.8 KB - evals/EVALUATION.md
f7f4a9c7411.5 KB - references/artifacts-and-targets.md
5dceccd55a2.1 KB - references/caching-and-gradle.md
2f7f316e622.6 KB - references/experimental.md
e0e83e36eb1.2 KB - references/exports-and-generated-code.md
76d94b9a081.5 KB - scripts/audit-native-build.sh
94af58014f6.0 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from Kotlin/kotlin-agent-skills8
Model Kotlin persistence code correctly for Spring Data JPA and Hibernate. Covers entity design, identity and equality, uniqueness constraints, relationships, fetch plans, and common ORM (Object-Relational Mapping) traps specific to Kotlin. Use when creating or reviewing JPA (Java Persistence API) e
Migrates Kotlin Multiplatform (KMP) projects to Android Gradle Plugin 9.0+. Handles plugin replacement (com.android.kotlin.multiplatform.library), module splitting, DSL migration, and the new default project structure. Use when upgrading AGP, when build fails due to KMP+AGP incompatibility, or when
Migrate KMP projects from CocoaPods (kotlin("native.cocoapods")) to Swift Package Manager (swiftPMDependencies DSL) — replaces pod() with swiftPackage(), transforms cocoapods.* imports to swiftPMImport.*, and reconfigures the Xcode project.
Load when porting, converting, or reimplementing a single Gradle plugin as a Kotlin Toolchain local plugin, or when mapping Gradle plugin concepts (Task, Extension, project.version, dependsOn, -P properties, afterEvaluate) to Toolchain analogs. Skip for migrating a whole Gradle project or authoring
Load when migrating or converting an entire Gradle Kotlin project (build.gradle(.kts), wrapper, libs.versions.toml, buildSrc) to the Kotlin Toolchain, including rewriting CI and replacing Gradle plugins that have no native Toolchain equivalent. Skip for porting one Gradle plugin or general Toolchain
Migrate Kotlin (and Java) code from kotlinx.collections.immutable 0.3.x / 0.4.x to the latest 0.5.x. The 0.5.x line renames every copy-returning method on PersistentList / PersistentMap / PersistentSet / PersistentCollection to a participial form per KEEP-0459 (add→adding, removeAt→removingAt, set→r
Use when converting Java source files to idiomatic Kotlin, when user mentions "java to kotlin", "j2k", "convert java", "migrate java to kotlin", or when working with .java files that need to become .kt files. Handles framework-aware conversion for Spring, Lombok, Hibernate, Jackson, Micronaut, Quark
Load when building, running, testing, packaging, linting, or configuring a Kotlin/Java project with the Kotlin Toolchain (JetBrains' unified CLI, formerly Amper), when scaffolding a new or greenfield Kotlin project, or when the repo has project.yaml, module.yaml, or a ./kotlin wrapper. Skip for exis
Related mobile skillsscan passed
PostHog error tracking for React Native
JetBrains Exposed ORM patterns including DSL queries, DAO pattern, transactions, HikariCP connection pooling, Flyway migrations, and repository pattern. Use when working with the Exposed ORM — DSL or DAO queries, transactions, pooling, or migrations.
Remove the DebugBridge SPM package and all #if DEBUG wiring from an iOS app. (gstack)
Test iOS apps in a simulator with XcodeBuildMCP. Use when iOS changes need simulator evidence before handoff.
Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).
AWS SDK for Swift development patterns. Use when writing Swift code that uses AWS services via aws-sdk-swift package.