Save 37% off PRO during our Black Friday Sale! »

Kotlin Native in 1.6

85637f06e3366e5cc4c84780cc346141?s=47 RyuNen344
November 16, 2021

Kotlin Native in 1.6

85637f06e3366e5cc4c84780cc346141?s=128

RyuNen344

November 16, 2021
Tweet

Transcript

  1. Kotlin/Native in 1.6 2011.11.16 Mobileษڧձ Wantedly × νʔϜϥϘ Bunjiro Miyoshi

  2. About Me • (ࣗশ)ϚϧνϓϥοτϑΥʔϜܳਓ • KMM, Flutter etc... • ΞΠίϯ͕ϒϩοίϦʔͩͬͨΓɺγϯόϧͩͬͨΓ

  3. KMM will go Beta in Spring 2022

  4. Kotlin/Native 1.6ͷ໨ۄػೳ ......ͷલʹ

  5. ͝ଘ͡Ͱ͔͢ʁ Kotlin/Native 1.5ͷػೳ

  6. Kotlin 1.5.0 • Performance޲্ • Memory Leak Checkerͷެ։ • ಺෦։ൃ༻ύϥϝʔλ͕ެ։͞Εͨ

  7. Kotlin 1.5.20 • Performance޲্ • KDocΛObjective-C Headerʹग़ྗՄೳʹͳͬͨ • JavaDocͷKotlinόʔδϣϯ(https://kotlinlang.org/docs/kotlin- doc.html)

    • Dokka(https://github.com/Kotlin/dokka)Λ࢖͏ͱ͓खܰʹυΩϡ ϝϯτΛੜ੒Ͱ͖Δ
  8. Kotlin 1.5.20 KDoc • build.gradleͰcompilerArgsʹ-Xexport-kdocΛ௥Ճ

  9. Kotlin 1.5.20 KDoc 👇

  10. Kotlin 1.5.30 • Apple Silicon Support • arm64ܥͷαϙʔτ • CocoaPods

    Gradle Pluginͷ֦ு • Swift 5.5 async/awaitޓ׵ੑ޲্ • Companion Objectͷޓ׵ੑ޲্
  11. Kotlin 1.5.30 CocoaPods Gradle Plugin

  12. Kotlin 1.5.30 Swift 5.5 async/await • kotlinͷsuspendؔ਺ͷޓ׵ࣗମ͸kotlin 1.4Ͱಋೖ • Swift/Objective-CڞʹCompletion

    Handlerͱͯ͠ఏڙ͞Ε͍ͯͨ • Swift5.5Ҏ߱ʹ͍ͭͯ͸async/awaitͱͯ͠kotlinͷsuspendؔ਺Λ ࢖͑Δ
  13. Kotlin 1.5.30 Companion Object 👉

  14. Kotlin/Native 1.6ͷ໨ۄػೳ ຊ୊ʹ໭ͬͯ

  15. ৽͍͠Memory Managementͷొ৔ (experimental)

  16. WARNING Kotlin 1.6 RC2Ͱͷ಺༰Ͱ͢ (લ೔ʹͳͬͯ1.6 Stable͕Release͞Ε·ͨ͠😢)

  17. େࡶ೺ʹݴ͏ͱ...... • Tracing Garbage Collection͕ಋೖ͞Εͨ • freeze, @SharedImmutable, @ThreadLocal౳ͷKotlin/Nativeಛ༗ͷه ड़͕ෆཁʹͳͬͨ*

  18. ݱঢ়ͷMemory Management....ͷલʹ JVM/android Swift, Objective-C/iOS Tracing Garbage Collection Automatic Reference

    Counting Full GCͷ૸Δͱ͢΂͕ͯࢭ·Δ͜ͱ͕͋Δ (Stop The World) compile timeʹΧ΢ϯτ͢ΔॲཧΛຒΊࠐΉ increment, decrement͢ΔॲཧͷͨΊϧʔϓ ౳ͷॲཧͰΦʔόʔϔου͕ൃੜ
  19. ݱঢ়ͷMemory Management 0ME /FX Deferred Reference Counting GC Stop The

    World mark and sweep GC εϨουͷϒϩοΫΛճආ͢Δඞཁ͕͋Δ(ཁ freeze) GCͷλΠϛϯάΛԆظͤ͞ΔͨΊස౓͸ݮΔ ͕ॲཧ͕࣌ؒ௕͘ͳΔ freeze͠ͳͯ͘΋εϨουΛލ͍ͰΦϒδΣΫ τͱϓϩύςΟʹΞΫηεͰ͖Δ* ύϑΥʔϚϯεѱ͍(εϨου͕ࢭ·Δ) ΞϧΰϦζϜ͸ݕ౼த
  20. Ͳ͏มΘΔʁ • ࠷্ҐϓϩύςΟͷ஗ԆॳظԽ • ࠷ॳʹΞΫηεͨ͠λΠϛϯάͰॳظԽ͞ΕΔΑ͏ʹ • ࠓޙ΋ϓϩάϥϜىಈ࣌ʹॳظԽͤ͞ͳ͚Ε͹ͳΒͳ͍΋ͷ͸ @EagerInitializationΛ෇༩ • ݪଇfreezeෆཁ

    • AtomicReference͸ඞཁ • by lazy {}͕εϨουηʔϑϞʔυΛαϙʔτ
  21. ࣮ࡍͷϝϞϦ࢖༻ྔͷΠϝʔδ • ը໘ભҠͱϦετੜ੒͢ΔΞϓϦ • Generate instanceϘλϯΛԡ͢ͱ data classͷϦετΛ10ສݸੜ੒͢Δ • Run

    GCϘλϯΛԡ͢ͱGCΛڧ੍త ʹ૸ΒͤΔ
  22. ࣮ࡍͷϝϞϦ࢖༻ྔͷΠϝʔδ ΞϓϦىಈ GCΛΩοΫ Ϧετը໘ʹભҠ 20ສݸͷϦετੜ੒ Emptyը໘ʹભҠ ݩը໘ʹ໭Δ ᶃ ᶄ ᶅ

    ᶆ ᶇ ᶈ
  23. ࣮ࡍͷϝϞϦ࢖༻ྔͷΠϝʔδ Old ᶃ ᶄ ᶅ ᶆ ᶇ ᶈ

  24. ࣮ࡍͷϝϞϦ࢖༻ྔͷΠϝʔδ New ᶃ ᶄ ᶅ ᶆ ᶇ ᶈ

  25. ࣮ࡍͷϝϞϦ࢖༻ྔͷΠϝʔδ • ࠓͷΞϧΰϦζϜͩͱKotlin/NativeଆͰॲཧதʹ࢖༻ͨ͠ϝϞϦ͕݁ ߏ࢒Δ • େ͛͞ͳྫͳͷͰ࣮࢖༻Ͱ͸ී௨ʹ࢖͑ͦ͏ 🤔Ͳ͏ͯ͠΋GCΛ૸Β͍ͤͨ৔߹΋͋Δ͔΋

  26. ௕͍ఀࢭ࣌ؒɾΩϧ ϦεΫΛݮΒͨ͢Ίʹ

  27. ProgrammaticallyʹGCΛΩοΫ͢Δ • GCͷΞϧΰϦζϜͷ੍ݶͱͯ͠εϨουͷఀࢭ࣌ؒ͸ώʔϓ಺ͷΦ ϒδΣΫτ਺ʹґଘ͢Δ • iOS͸ΞϓϦͷঢ়ଶΛѻ͏ػೳ͕ͳ͍ͷͰόοΫάϥ΢ϯυʹҠߦ͠ ͨ౳ΛΩοΫʹGCΛ૸ΒͤΔ͜ͱ͕Ͱ͖ͳ͍ͨΊOSʹΞϓϦ͕Ωϧ ͞ΕΔ֬཰͕ߴ·Δ 👉ProgrammaticallyʹGCΛΩοΫͨ͘͠ͳΔ

  28. ProgrammaticallyʹGCΛΩοΫ͢Δ • kotlin.native.internalʹఆٛ͞Ε͍ͯΔGC.ktͱCleaner.ktΛ࢖༻͢Δ • ͦΕͧΕϦιʔεղফʹఏڙ͞Ε͍ͯΔinterface • C++ίʔυʹinteropͯ͋͠Γɺͦ͜ͰϝϞϦղ์Λߦ͏ • σϑΥϧτͰ͸ެ։͞Ε͍ͯͳ͍ͷͰwrapper functionΛ༻ҙͯ͠ݺͼग़ͤΔ

    Α͏ʹͯ͋͛͠Δ • جຊతʹ͸Kotlin/Native Runtime͕ࣗಈͰGCΛΩοΫ͢ΔͷͰ࢖༻ස౓͸௿ ͍(͸ͣ)
  29. ProgrammaticallyʹGCΛΩοΫ͢Δ ࣗಈͰ૸ΔGCͰղܾͰ͖ͳ͍΋ͷʹؔ͠ ͯ͸ࠨهͷϝιουΛୟ͍ͯ΍Δ(ex. AppDelegate#applicationDidEnterBackground)

  30. ϥΠϒϥϦͷରԠঢ়گ • Ktor • 2.0.0ͰରԠ͞Εͨόʔδϣϯ͕stableʹͳΔ • eapΛࢼ͢৔߹͸1.6.2-native-mm-eap-196 • Coroutine •

    1.5.3ͰstableʹͳΓͦ͏ • eapΛࢼ͢৔߹͸1.5.1-new-mm-dev2 • SQLDelight • ಈ͔ͳ͍ࢫͷissueཱ͕͍ͬͯΔ (https://github.com/cashapp/sqldelight/issues/2556) • eapʹରԠ͸͠ͳ͍༷ࢠͳͷͰkotlinଆͷnew mm͕ରԠ͞Ε͔ͯΒʹͳΓͦ͏
  31. ·ͱΊ • Kotlin/Nativeʹ৽͍͠ϝϞϦϚωʔδϝϯτͷ࢓૊Έ͕ಋೖ͞Εɺ Kotlin/Nativeಛ༗ͷهड़͕ݮΒͤΔΑ͏ʹͳͬͨ • KtorͷHttpClientEngineੜ੒पΓ͕͔ͳΓָʹͳͬͯخ͍͠ • ύϑΥʔϚϯε͸·ͩ·ͩ޲্͞Εͦ͏

  32. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

  33. ࢀߟࢿྉ • σϞΞϓϦ(https://github.com/RyuNen344/koin-mpp-sample/releases/tag/newmm) • Kotlin/Native Memory Management Update(https://blog.jetbrains.com/kotlin/ 2021/05/kotlin-native-memory-management-update/) •

    Prototype a new garbage collector(https://youtrack.jetbrains.com/issue/KT-42296) • Try the New Kotlin/Native Memory Manager Development Preview(https:// blog.jetbrains.com/kotlin/2021/08/try-the-new-kotlin-native-memory-manager- development-preview/) • NEW_MM.md(https://github.com/JetBrains/kotlin/blob/master/kotlin-native/ NEW_MM.md)