I wonder if there are plans or perhaps some switch...
# kotlin-native
t
I wonder if there are plans or perhaps some switches/options I can turn on to speed up XCFramework generation. See this example: 13 seconds to compile, but over 6 minutes to link! This is on an M4 Pro machine too. On a CI/CD system, it takes sooo much longer, and costs a lot more, making it prohibitive to use in production. 😞 Thank you.
➕ 7
e
It's a pain that we are working on from many angles, you're definitely not alone. It's sadly also one of those topics without magic bullets, but here's what has been done recently or will be available: 1. In Kotlin 2.3.0 Kotlin/Native has released improvements to linking for release tasks, with some of our benchmarks seeing a 40% improvement. 2. In Kotlin 2.4.20 incremental compilation will be enabled by default, though this mainly benefits debug builds. 3. We noticed that many user projects we investigate for build speed issues have configurations or modularization that could be improved. We have documented this, but realistically this is hard to do manually if you are not familiar. We have a PR in review for an agent skill that improves native build times for you, feel free to try this out already. Even after all this work, we know there is still more room for improvement. Could you share a little bit more about the size and nature of your project? Does it have a lot of modules or are they maybe very large? Do you maybe have large native dependencies you rely on? Do you use release builds for all your CI/CD runs or do you run only run release for actual release pipelines? Any context can help us with improving further!
t
Our project includes three modules being built into one XCFramework: • core: pure KMP with some basic expect/actuals • ui: CMP UI, including maybe 30 Compose Views used cross-platform. also all the related ViewModels • ecpsdk: wrapper around some native payment SDKs, so includes cinterop around two iOS frameworks Only have targets for iosArm64 and iosSimulatorArm64. We also use a good number of third-party libs, including moko permissions, datetime, etc etc.
t
FYI: we've merged mentioned above agent skill
🙌 1
👀 1
e
Hopefully the skill can help a bit as a quick win! Trying to avoid release builds until the very last testing before publishing is what we can recommend right now. I spoke earlier today with the team about it and the linking steps do a lot of optimization that you benefit from at runtime. KT-49385 could help for sure, but this process is very RAM hungry and for many users (especially on CI) could result in out of memory errors. Making this available as opt-in could be an option. There are also other ideas to improve linking, but I don't have more specific things I can share at this time.
e
true, native linking can use a lot of memory (not just Kotlin). Gradle does already limit how many process isolation workers are run in parallel based on their declared heap sizes and available system memory, but I don't know how you'd estimate
lld
footprint up front, so the parallelism may need to be user configurable
t
we are really aiming with KT-70915 Limit parallelism on KotlinNativeLink tasks to land in 2.5.0, so link tasks parallelism could be controlled separately from Gradle workers knob
t
I am glad to hear about speeding things up via parallelism. But from my experience, it is the link process itself that takes too long, whether you are running target architecture or more. So I suspect that a bigger payoff would be to improve the link procedure itself. Thanks.