iOS共享模块的Kotlin Multiplatform Mobile有多本地化?

huangapple go评论86阅读模式
英文:

How native is the iOS shared module of Kotlin Multiplatform Mobile?

问题

Kotlin Multiplatform Mobile 共享模块在 iOS 平台上是如何实现的?它是被转译成 Swift 代码还是采用其他方式?与 Swift 代码相比,性能如何?

英文:

How is the shared module of Kotlin Multiplatform Mobile realized on the iOS platform? Is it transpiled to Swift code or how does that work? How performant is it compared to Swift code?

答案1

得分: 2

"Kotlin/Native 是一种将 Kotlin 代码编译成本机二进制代码的技术,可以在没有虚拟机的情况下运行。Kotlin/Native 包括一个基于 LLVM 的 Kotlin 编译器后端和 Kotlin 标准库的本机实现。"

"在为 iOS 编译 Kotlin 时,它使用绑定来访问标准 iOS 库,因此性能完全是本机的。例如,如果不仅执行系统调用,还执行一些计算:Kotlin Native 使用 LLVM 进行编译(不是 转译 为 Swift),与 Swift 一样,这意味着会涉及相同的优化。此外,与 ObjC/Swift 交互时,Kotlin 为其对象创建包含引用计数器的包装器(与 ObjC/Swift ARC 运行时相同),这也有助于更本机的交互。"

"所以,是的,它在某些情况下可能会更快或更慢,但它相当本机。"

英文:

"Kotlin/Native is a technology for compiling Kotlin code to native binaries which can run without a virtual machine. Kotlin/Native includes an LLVM-based backend for the Kotlin compiler and a native implementation of the Kotlin standard library."

When you compile kotlin for iOS, it uses the standard iOS library via bindings, so the performance here is completely native. If, for example, not just syscalls are performed but some calculations: kotlin native is compiled using llvm(not transpiles to swift), as well as swift, which means that the same optimizations will be involved. Also, when interacting with ObjC/Swift, kotlin creates wrappers for its objects containing reference counters (the same as in the ObjC/Swift ARC runtime) which also contributes to a more native interaction.

So yea, it can be faster or slower in some cases, but it's pretty native.

huangapple
  • 本文由 发表于 2023年4月10日 21:25:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977533.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定