Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin/NativeのNew Memory Managerに移行しよう | Kotlin Fest 2022

Seiya Kokushi
December 10, 2022

Kotlin/NativeのNew Memory Managerに移行しよう | Kotlin Fest 2022

Kotlinでマルチプラットフォームのモバイルアプリケーション開発を行えるKotlin Multiplatfrom Mobileが2022年10月にBetaとなりました。
JetBrainsはKMM Betaに向けてさまざまな改善に取り組んできましたが、その中でもNew Memory Managerに注力していました。旧Memory ManagerのKotlin/NativeにおけるKotlin coroutinesや並列、非同期処理の課題がKotlin 1.7.20で改善され、新Memory ManagerはBetaステータスとなっています。
本セッションでは、旧Memory Managerの課題とこれまでの対処方法、新旧の比較(仕組み、実装方法、パフォーマンス)、マイグレーション方法、関連ライブラリ(Kotlin coroutines、Ktor)の変更点などをご紹介します。

Seiya Kokushi

December 10, 2022
Tweet

More Decks by Seiya Kokushi

Other Decks in Technology

Transcript

  1. גࣜձࣾαΠόʔΤʔδΣϯτ
    ᅳࢣ੣໵!SPOOOOO@KQ
    ,PUMJO/BUJWFͷ/FX.FNPSZ
    .BOBHFSʹҠߦ͠Α͏

    View full-size slide

  2. ,PUMJO.VMUJQMBUGPSN.PCJMF#FUB
    )JTUPSZPG/FX.FNPSZ.BOBHFS
    8IZ/FX.FNPSZ.BOBHFS/FFEFE
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    (BSCBHF$PMMFDUPS"MHPSJUIN
    .FNPSZ.BOBHFS"QQSPBDI
    /FX.FNPSZ.BOBHFS7FSTJPOT
    .JHSBUFUP/FX.FNPSZ.BOBHFS
    /FX.FNPSZ.BOBHFS'FBUVSFT

    View full-size slide

  3. ,PUMJO.VMUJQMBUGPSN.PCJMF#FUB

    View full-size slide

  4. IUUQTZPVUVCF$OH,%(#M'YL

    View full-size slide

  5. ,PUMJO.VMUJQMBUGPSN.PCJMF#FUB
    ɾ,PUMJO/BUJWF/FX.FNPSZ.BOBHFS
    ɾ,PUMJO/BUJWFCJOBSZDPNQBUJCJMJUZ
    ɾ)JFSBSDIJDBMQSPKFDUTUSVDUVSFTVQQPSU
    ɾ"QQMFJOUFHSBUJPOUPPMJOH
    ɾ/FXNVMUJQMBUGPSNCVJMEUPPMJOHBSDIJUFDUVSF
    ʜ
    IUUQTZPVUVCF-&%Z9$-YL

    View full-size slide

  6. ,PUMJO.VMUJQMBUGPSN.PCJMF#FUB
    IUUQTZPVUVCF-&%Z9$-YL
    ɾ,PUMJO/BUJWF/FX.FNPSZ.BOBHFS
    ɾ,PUMJO/BUJWFCJOBSZDPNQBUJCJMJUZ
    ɾ)JFSBSDIJDBMQSPKFDUTUSVDUVSFTVQQPSU
    ɾ"QQMFJOUFHSBUJPOUPPMJOH
    ɾ/FXNVMUJQMBUGPSNCVJMEUPPMJOHBSDIJUFDUVSF
    ʜ

    View full-size slide

  7. ,PUMJO.VMUJQMBUGPSN.PCJMF#FUB
    IUUQTZPVUVCF-&%Z9$-YL
    IUUQTCMPHKFUCSBJOTDPNLPUMJOLNNCFUB

    View full-size slide

  8. )JTUPSZPG/FX.FNPSZ.BOBHFS

    View full-size slide

  9. +VMZ .BZ "VHVTU 4FQUFNCFS
    )JTUPSZPG/FX.FNPSZ.BOBHFS
    .BZ

    View full-size slide

  10. IUUQTCMPHKFUCSBJOTDPNLPUMJOLPUMJOOBUJWFNFNPSZNBOBHFNFOUSPBENBQ
    ɾ,PUMJO/BUJWFͷ৽͍͠.FNPSZ.BOBHFS
    Λ։ൃ͢ΔܭըΛൃද
    ɾ͜Ε·Ͱͷ.FNPSZ.BOBHFSͷ࢓૊Έͷ࠾
    ༻ཧ༝΍໰୊఺ʹ͍ͭͯ΋ݴٴ
    )JTUPSZPG/FX.FNPSZ.BOBHFS
    +VMZ .BZ "VHVTU 4FQUFNCFS
    .BZ

    View full-size slide

  11. IUUQTCMPHKFUCSBJOTDPNLPUMJOLPUMJOOBUJWFNFNPSZNBOBHFNFOUVQEBUF
    ɾ৽͍͠.FNPSZ.BOBHFSͷਐḿͱͦͷ
    (BSCBHF$PMMFDUPSͷઃܭํ਑Λެ։
    ɾ࠾༻Ξϓϩʔνͱ࣮૷ܭը΋ڞ༗
    )JTUPSZPG/FX.FNPSZ.BOBHFS
    +VMZ .BZ "VHVTU 4FQUFNCFS
    .BZ

    View full-size slide

  12. IUUQTCMPHKFUCSBJOTDPNLPUMJOUSZUIFOFXLPUMJOOBUJWFNFNPSZNBOBHFSEFWFMPQNFOUQSFWJFX
    ɾ%FWFMPQNFOU1SFWJFXΛެ։ ,PUMJO.

    ɾ"MQIB൛Λެ։ ,PUMJO

    )JTUPSZPG/FX.FNPSZ.BOBHFS
    +VMZ .BZ "VHVTU 4FQUFNCFS
    .BZ

    View full-size slide

  13. )JTUPSZPG/FX.FNPSZ.BOBHFS
    IUUQTZPVUVCF0(OQPX+H& U
    ɾ,PUMJOͰ/FX.FNPSZ.BOBHFS͕

    σϑΥϧτͰ༗ޮʹ
    ɾ/FX.FNPSZ.BOBHFSͱ,PUMJO.VMUJQMBUGPSN
    .PCJMF͕#FUBʹ
    +VMZ .BZ "VHVTU 4FQUFNCFS
    .BZ

    View full-size slide

  14. 8IZ/FX.FNPSZ.BOBHFS/FFEFE

    View full-size slide

  15. 8IZ/FX.FNPSZ.BOBHFS/FFEFE
    ,PUMJO.VMUJQMBUGPSNͷڧΈ͸ʁ
    ɾ1MBUGPSNؒͷ࣮૷Λڞ௨ԽͰ͖Δ
    ɾ֤1MBUGPSNΛؾʹ͢Δͷ͸ɺಛ༗ͷ"1*Λ࢖࣮ͬͯ૷͢Δ৔߹
    DPNNPO.BJO
    BOESPJE.BJO JPT.BJO

    View full-size slide

  16. ,PUMJO.VMUJQMBUGPSNͷڧΈ͸ʁ
    ɾฒߦॲཧͷ࣮૷ʹؔͯ͠ɺ,PUMJO/BUJWFಛ༗ͷ͓࡞๏͕ඞཁ
    ɾLPUMJOYDPSPVUJOFTͰϝϞϦϦʔΫ͕ൃੜ͢Δ͜ͱ͕͋Δ
    چ.FNPSZ.BOBHFSʹΑΔ੍໿ͱ՝୊
    ,PUMJO/BUJWFΛߟྀ࣮ͨ͠૷ɾ։ൃऀମݧ͕ѱ͍
    ˠ,PUMJO.VMUJQMBUGPSNͷීٴΛ๦͛Δͱ൑அ
    8IZ/FX.FNPSZ.BOBHFS/FFEFE

    View full-size slide

  17. $PODVSSFODZPO0ME.FNPSZ.BOBHFS

    View full-size slide

  18. $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    ,PUMJO/BUJWFͷϚϧνεϨουॲཧʹ͓͚Δϧʔϧ
    Մมͳঢ়ଶγϯάϧεϨου
    ෆมͳঢ়ଶϚϧνεϨου

    View full-size slide

  19. $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    ɾঢ়ଶ͕ՄมͰ͋Δ৔߹͸ෳ਺εϨου͔Βࢀরɾૢ࡞Ͱ͖ͳ͍
    ɾ6*ͷߋ৽͕ϝΠϯεϨουҎ֎͔Βߦ͑ͳ੍͍໿ʹࣅ͍ͯΔ
    Մมͳঢ়ଶγϯάϧεϨου

    View full-size slide

  20. $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    ෆมͳঢ়ଶϚϧνεϨου
    ɾঢ়ଶ͕ෆมͰ͋Ε͹ෳ਺εϨου͔Βࢀরɾૢ࡞Ͱ͖Δ
    ɾෆมWBM ෆมGSP[FOTUBUF

    View full-size slide

  21. ɾ,PUMJO/BUJWFͰ͸ϥϯλΠϜͰՄมɾෆมΛධՁ͢Δඞཁ͕͋Δ

    ˠϥϯλΠϜͰෆมͰ͋Δ͜ͱΛࣔ͢GSP[FOTUBUF͕ඞཁʹͳΔ
    ɾ,PUMJO/BUJWFʹ͓͍ͯ͸ɺ͍͔ͳΔΦϒδΣΫτ΋GSFF[FՄೳ
    data class SomeData(val s: String, val i: Int) // i is stable


    data class SomeData(val s: String, val i: SomeInterface) // i is unstable
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS

    View full-size slide

  22. 'SP[FOTUBUFͷಛ௃
    ɾঢ়ଶΛม͑Δ͜ͱ͕Ͱ͖ͳ͍
    ɾঢ়ଶΛม͑Α͏ͱ͢Δͱ*OWBMJE.VUBCJMJUZ&YDFQUJPO͕ൃੜ͢Δ
    ɾ'SP[FOTUBUFͷ఻೻
    ɾΦϒδΣΫτΛGSFF[F͢ΔͱɺࢠͷΦϒδΣΫτ΋࠶ىతʹGSFF[F
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS

    View full-size slide

  23. data class MoreData(val strData: String, var width: Float)


    data class SomeData(val moreData: MoreData, var count: Int)


    //...


    val sd = SomeData(MoreData("abc", 10.0), 0)


    sd.freeze()
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS

    View full-size slide

  24. GSFF[F
    ؔ਺
    ɾ,PUMJO/BUJWFͷGSFF[F
    ؔ਺ʹΑͬͯɺΦϒδΣΫτΛGSFF[FͰ͖Δ
    ɾ೚ҙͷΦϒδΣΫτʹରͯ͠GSFF[F
    ͨ࣌͠఺ͰɺͦͷΦϒδΣΫτ͕
    ࢀর͍ͯ͠ΔΦϒδΣΫτ΋࠶ىతʹGSFF[F͞ΕΔ
    ɾGSFF[F
    ͸ෆՄٯૢ࡞ͳͷͰɺVOGSFF[Fͤ͞Δ͜ͱ͸Ͱ͖ͳ͍
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS

    View full-size slide

  25. άϩʔόϧΦϒδΣΫτ
    ɾGSFF[F
    Λݺ͹ͳͯ͘΋GSFF[F͞ΕΔ
    ɾ͍͔ͳΔεϨου͔Β΋ΞΫηεͰ͖Δ͕ෆมͰͳ͍ͱ͍͚ͳ͍
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    object SomeState {


    var count = 0


    fun add() {


    count++ //This will throw an exception


    }


    }

    View full-size slide

  26. άϩʔόϧΦϒδΣΫτ
    ɾ!5ISFBE-PDBMΛ࢖͏͜ͱͰෳ਺εϨουͰͷૢ࡞͕Մೳ
    ɾεϨου͝ͱʹ஋Λίϐʔ͢ΔͨΊεϨου͝ͱʹ஋͕ҟͳΔՄೳੑ
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    @ThreadLocal


    object SomeState{


    var count = 0


    fun add(){


    count++ //👍


    }


    }

    View full-size slide

  27. άϩʔόϧϓϩύςΟ
    ɾWBSͰఆٛͰ͖Δ͕ɺϝΠϯεϨου͔ΒͷΈࢀরɾૢ࡞͕Մೳ
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    @SharedImmutable ϝΠϯεϨουҎ֎͔Β΋ࢀরͰ͖Δ͕GSFF[F͞ΕΔ
    @ThreadLocal
    εϨου͝ͱʹ஋ͷίϐʔΛ࡞੒͢ΔͨΊɺෳ਺εϨ
    ουͰͷࢀরɾૢ࡞͕Մೳ

    View full-size slide

  28. εϨουηʔϑΛ࣮ݱ͢ΔͨΊʹ
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    "UPNJDT
    5ISFBEJTPMBUFE4UBUF

    View full-size slide

  29. $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    "UPNJDT
    ɾ,PUMJO/BUJWFͰ͸ɺ஋ͷมߋ͕Մೳͳ͕ΒGSFF[FͰ͖Δੑ࣭Λ࣋ͬͨ
    "UPNJD9YYΫϥεΛఏڙ͍ͯ͠Δ
    ɾ"UPNJD3FGFSFODF͸ɺϦετͷૢ࡞ͱ͍ͬͨಛఆεϨουͰίετ͔
    ͔Δૢ࡞Λߦ͏৔߹ʹεϨουηʔϑʹͳΒͳ͍Մೳੑ͕͋Δ

    View full-size slide

  30. $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    5ISFBEJTPMBUFE4UBUF
    ɾՄมͳঢ়ଶΛಛఆͷεϨουʹด͡ࠐΊɺผεϨου͔Βͦͷঢ়ଶʹ
    ରͯ͠΍ΓͱΓΛߦ͏
    ɾҟͳΔεϨουͷ΍ΓͱΓΛಉ͡XPSLRVFVF্Ͱߦ͏͜ͱͰɺεϨ
    ουηʔϑΛ࣮ݱ

    View full-size slide

  31. "UPNJD3FGFSFODFWT5ISFBEJTPMBUFE4UBUF
    $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    ɾγϯϓϧͳ஋΍খ͍͞ΦϒδΣΫτ͸"UPNJD3FGFSFODF͕؆ܿͰѻ͍
    ΍͍͢
    ɾ஋ͷૢ࡞ʹίετ͕͔͔Δ৔߹΍ϦετͰ͸ɺSBDFDPOEJUJPOΛ๷͙
    ͨΊʹ5ISFBEJTPMBUFE4UBUFΛར༻͢Δ

    View full-size slide

  32. $PODVSSFODZPO0ME.FNPSZ.BOBHFS
    ɾOBUJWFNUϒϥϯνͰ੍໿ʹରԠ࣮ͨ͠૷͕։ൃ͞Ε͍ͯΔ
    ɾGSFF[Fޙ΋஋ͷมߋ͕Մೳͳ"UPNJD9YYͷ࣮૷Λར༻
    LPUMJOYDPSPVUJOFT
    "UPNJDΫϥεͷࢀরΛ௥੻Ͱ͖ͣɺϝϞϦϦʔΫ͢Δέʔε͕ଘࡏ

    View full-size slide

  33. IUUQTLPUMJOMBOHPSHEPDTOBUJWFJNNVUBCJMJUZIUNM

    View full-size slide

  34. (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  35. (BSCBHF$PMMFDUPS"MHPSJUIN
    3FGFSFODFDPVOUJOH($
    ɾΦϒδΣΫτʹࢀর਺ ϙΠϯλͷ਺
    Λ෇ਵ͢Δ
    ɾࢀর਺ʹͳͬͨΦϒδΣΫτΛճऩ͢Δ

    View full-size slide

  36. SPPU
    3FGFSFODFDPVOUJOH($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  37. SPPU






    3FGFSFODFDPVOUJOH($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  38. SPPU





    3FGFSFODFDPVOUJOH($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  39. SPPU





    ౸ୡෆೳˠϝϞϦϦʔΫ
    3FGFSFODFDPVOUJOH($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  40. 5SBDJOH 5SBWFSTJOH
    ($
    ɾϧʔτ͔ΒϙΠϯλΛͨͲΓɺ౸ୡՄೳͳΦϒδΣΫτΛൃݟ
    ɾ౸ୡͰ͖ͳ͍ΦϒδΣΫτΛճऩ
    ɾ͞Βʹ͍͔ͭ͘छྨ͕͋Δ .BSL4XFFQ($ $PQZ($

    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  41. SPPU
    5SBDJOH 5SBWFSTJOH
    ($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  42. SPPU
    5SBDJOH 5SBWFSTJOH
    ($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  43. SPPU
    5SBDJOH 5SBWFSTJOH
    ($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  44. SPPU
    5SBDJOH 5SBWFSTJOH
    ($
    (BSCBHF$PMMFDUPS"MHPSJUIN

    View full-size slide

  45. 3FGFSFODFDPVOUJOHWT5SBDJOH
    5SBDJOH 5SBWFSTJOH
    ($
    3FGFSFODFDPVOUJOH($
    ɾ࣮૷͕༰қͰγϯϓϧ
    ɾࢀর਺ͷมߋΛτϦΨʔʹͰ͖Δ
    ɾϝϞϦϦʔΫ͕ى͖΍͍͢
    ɾ࣮૷͕೉͍͠
    ɾޮ཰తʹ($Λ૸ΒͤΔ͜ͱ͕೉͍͠
    ɾϝϞϦϦʔΫΛ๷͗΍͍͢

    View full-size slide

  46. .FNPSZ.BOBHFS"QQSPBDI

    View full-size slide

  47. 0ME.FNPSZ.BOBHFS"QQSPBDI
    ɾ؆ܿ͞ͱ͍͏؍఺͔Β࠾༻
    ɾ3FGFSFODFDPVOUJOH($ʹΑΔ॥؀ࢀরͷ໰୊͸ɺผͷΞϧΰϦζϜ USJBM
    EFMFUJPO
    Λ૊Έ߹ΘͤͯରԠ
    ɾϝϞϦׂΓ౰͕ͯසൃ͢ΔΞϓϦέʔγϣϯ΍ϚϧνεϨουͱฒߦॲཧ͕ࠞ
    ࡏ͢ΔΞϓϦέʔγϣϯͰύϑΥʔϚϯε͕γϏΞʹͳΓGSFF[Fͷಋೖ
    3FGFSFODFDPVOUJOH($

    View full-size slide

  48. /FX.FNPSZ.BOBHFS"QQSPBDI
    ɾ3FGFSFODFDPVOUJOHΑΓ΋ॊೈͰνϡʔχϯά͠΍͍͢
    ɾϚϧνεϨουΞϓϦέʔγϣϯʹ͓͚Δཁ݅ʹϑΟοτ͠΍͍͢
    ɾϥϯλΠϜͱίϯύΠϥͷ࣮૷͕ඇৗʹ೉͍͠ͷ͕ܽ఺
    ɾ͞·͟·ͳΞϧΰϦζϜ΍ͦͷ૊Έ߹Θͤͷ($Λར༻Ͱ͖ΔΑ͏ʹ($Λઃܭ
    5SBDJOH 5SBWFSTJOH
    ($

    View full-size slide

  49. /FX.FNPSZ.BOBHFS7FSTJPOT

    View full-size slide

  50. /FX.FNPSZ.BOBHFS7FSTJPOT
    ɾγϯϓϧͳTUPQUIFXPSMENBSLTXFFQUSBDJOH($Λ࣮૷
    ɾGSFF[Fͳ͠ʹ͋ΒΏΔεϨου͔ΒΦϒδΣΫτ΍ϓϩύςΟͷࢀর͕Մೳʹ
    ɾTUEMJC LPUMJOYDPSPVUJOFT ,UPS$MJFOUͰ/FX.FNPSZ.BOBHFSʹରԠ
    IUUQTZPVUSBDLKFUCSBJOTDPNJTTVF,51SPUPUZQFBOFXHBSCBHFDPMMFDUPS
    1SPUPUZQF ,PUMJO.

    View full-size slide

  51. ɾύϑΥʔϚϯεվળͱ҆ఆੑͷ޲্
    ɾ($ͷTXFFQϑΣʔζΛฒߦ࣮ߦՄೳʹ
    ɾ/FX.FNPSZ.BOBHFS͕༗ޮͳࡍʹGSFF[F͕σϑΥϧτͰແޮʹ
    IUUQTZPVUSBDLKFUCSBJOTDPNJTTVF,51SPNPUFOFXNFNPSZNBOBHFSUP"MQIB
    "MQIB ,PUMJO

    /FX.FNPSZ.BOBHFS7FSTJPOT

    View full-size slide

  52. ɾߋͳΔύϑΥʔϚϯεվળ
    ɾ($ͷεέδϡʔϥΛޮ཰ԽɺώʔϓαΠζΛεέʔϥϒϧʹ
    ɾσόοάϏϧυͷόΠφϦΛ࠷దԽ͠࠷େͰͷ࣮ߦ࣌ؒվળ
    ɾ/FX.FNPSZ.BOBHFS͕σϑΥϧτͰ༗ޮʹ
    IUUQTZPVUSBDLKFUCSBJOTDPNJTTVF,51SPNPUFOFXNFNPSZNBOBHFSUP#FUBBOEFOBCMFJUCZEFGBVMU
    #FUB ,PUMJO

    /FX.FNPSZ.BOBHFS7FSTJPOT

    View full-size slide

  53. .JHSBUFUP/FX.FNPSZ.BOBHFS

    View full-size slide

  54. .JHSBUFUP/FX.FNPSZ.BOBHFS
    IUUQTHJUIVCDPN+FU#SBJOTLPUMJOCMPCWLPUMJOOBUJWF/&[email protected]
    ,PUMJO.d
    kotlin.native.binary.memoryModel=experimental
    kotlin.targets.withType(KotlinNativeTarget::class.java) {
    binaries.all {
    binaryOptions["memoryModel"] = "experimental"
    }
    }
    ɾ/FX.FNPSZ.BOBHFSΛ༗ޮʹ͢ΔͨΊʹͲͪΒ͔ͷઃఆ͕ඞཁ
    HSBEMFQSPQFSUJFT CVJMEHSBEMFLUT

    View full-size slide

  55. .JHSBUFUP/FX.FNPSZ.BOBHFS
    IUUQTHJUIVCDPN+FU#SBJOTLPUMJOCMPCWLPUMJOOBUJWF/&[email protected]
    ɾOBUJWFNUͷόʔδϣϯΛ࢖Θͳ͍͍ͯ͘
    LPUMJOYDPSPVUJOFT

    LUPS OFXNNFBQ

    ɾσϑΥϧτͷFOHJOFͩͱྫ֎͕ൃੜ͢ΔͷͰɺ*PT͔ͦͷଞͷFOHJOFΛ࢖͏
    ,PUMJO.d

    View full-size slide

  56. .JHSBUFUP/FX.FNPSZ.BOBHFS
    IUUQTHJUIVCDPN+FU#SBJOTLPUMJOCMPCWLPUMJOOBUJWF/&[email protected]
    ɾγϯάϧεϨου͔ͭTUPQUIFXPSMEͷNBSLTXFFQΞϧΰϦζϜΛ
    ࠾༻͍ͯ͠ΔͨΊɺύϑΥʔϚϯεʹӨڹ͕ग़Δ
    ɾίϯύΠϥΩϟογϡ͕αϙʔτ͞Εͯͳ͍ͨΊɺEFCVHόΠφϦͷί
    ϯύΠϧʹ͕͔͔࣌ؒΔ
    ,PUMJO.d
    ஫ҙࣄ߲

    View full-size slide

  57. .JHSBUFUP/FX.FNPSZ.BOBHFS
    IUUQTLPUMJOMBOHPSHEPDTOBUJWFNJHSBUJPOHVJEFIUNM
    ɾ/FX.FNPSZ.BOBHFS͸σϑΥϧτͰ༗ޮ
    ɾ0ME.FNPSZ.BOBHFSΛ࢖͏͜ͱ΋Ͱ͖Δ͕ɺίϯύΠϥΩϟογϡ
    ͕ޮ͔ͳ͍ͷͰίϯύΠϧ͕࣌ؒ௕͘ͳΔͷͰ஫ҙ
    HSBEMFQSPQFSUJFT
    kotlin.native.binary.memoryModel=strict
    ,PUMJOd

    View full-size slide

  58. .JHSBUFUP/FX.FNPSZ.BOBHFS
    IUUQTLPUMJOMBOHPSHEPDTOBUJWFNJHSBUJPOHVJEFIUNM
    ɾGSFF[Fͤͣͱ΋͍͔ͳΔεϨου͔Β΋ΦϒδΣΫτͷ
    ࢀরɺૢ࡞͕Մೳ
    ɾ"UPNJD3FGFSFODFΛؚΜͩ॥؀ࢀরͰ͋ͬͯ΋

    ϝϞϦϦʔΫ͠ͳ͘ͳͬͨ
    ɾάϩʔόϧม਺͸஗ԆॳظԽ͞ΕΔΑ͏ʹ

    !&BHFS*OJUJBMJ[BUJPOͰ஗ԆॳظԽ͞Εͳ͍Α͏ʹͰ͖Δ

    @SharedImmutable
    freeze()
    isFrozen
    ensureNeverFrozen()
    ,PUMJOd

    View full-size slide

  59. .JHSBUFUP/FX.FNPSZ.BOBHFS
    IUUQTLPUMJOMBOHPSHEPDTOBUJWFNJHSBUJPOHVJEFIUNM
    ɾಛʹϚΠάϨʔγϣϯ͸ෆཁ
    ɾ͔Β,PUMJOʹґଘ
    ɾ/FX.FNPSZ.BOBHFSʹؔ͢ΔϚΠάϨʔγϣϯ͸ෆཁ
    ,PUMJOd
    LPUMJOYDPSPVUJOFT d

    LUPS d

    View full-size slide

  60. .JHSBUFUP/FX.FNPSZ.BOBHFS
    IUUQTLUPSJPEPDTNJHSBUJOHIUNM
    ,PUMJOd

    View full-size slide

  61. /FX.FNPSZ.BOBHFS'FBUVSFT

    View full-size slide

  62. /FX.FNPSZ.BOBHFS'FBUVSFT
    IUUQTLPUMJOMBOHPSHEPDTOBUJWFNFNPSZNBOBHFSIUN
    !4IBSFE*NNVUBCMFͷάϩʔόϧม਺͸GSFF[F͞Εͳ͍͕ɺ
    GSFF[F
    ΛݺͿͱGSFF[F͞ΕΔ
    kotlin.native.binary.freezing=disabled // explicitOnly
    kotlin.targets.withType(KotlinNativeTarget::class.java) {
    binaries.all {
    binaryOptions["freezing"] = “disabled" // “explicitOnly”
    }
    }
    HSBEMFQSPQFSUJFT CVJMEHSBEMFLUT
    ґଘ͍ͯ͠ΔϥΠϒϥϦ͕GSFF[F͢Δέʔε
    ,PUMJO.d
    disabled
    explicitOnly
    GSFF[F
    ΛݺΜͰ΋Կ΋͠ͳ͍

    View full-size slide

  63. IUUQTLPUMJOMBOHPSHEPDTOBUJWFNFNPSZNBOBHFSIUN
    ɾLPUMJOOBUJWFJOUFSOBM($DPMMFDU
    Ͱڧ੍తʹಈ࡞ͤ͞Δ͜ͱ͕Ͱ͖Δ
    ,PUMJOd
    ($Λ໌ࣔతʹૢ࡞͢Δ
    ($Λແޮʹ͢Δ
    ɾςετͳͲ($Λಈ͔ͨ͘͠ͳ͍৔߹͸(SBEMFͷϑϥά 9HDOPPQ
    Λઃఆ
    /FX.FNPSZ.BOBHFS'FBUVSFT

    View full-size slide

  64. IUUQTHJUIVCDPNNJDSPTPGUNJNBMMPD
    ɾ.FNPSZ.BOBHFSͷύϑΥʔϚϯε͸ઈ͑ͣվળ͍ͯ͠ΔͷͰɺ,PUMJOͷό
    ʔδϣϯΛ্͛ͯվળ͢Δ͔֬ೝ͢Δ
    ɾͦΕͰ΋վળ͠ͳ͍έʔεͰ͸NJNBMMPDΛར༻ͯ͠ΈΔ
    HSBEMFQSPQFSUJFT ,PUMJO#FUBҎ߱

    ύϑΥʔϚϯε͸͍͍͕৴པੑ͕௿Լ͢ΔՄೳੑ͋Γ
    kotlin.native.binary.mimallocUseCompaction=true
    (SBEMFͷίϯύϧΦϓγϣϯ
    -Xallocator=std
    ,PUMJOd
    ($ͷύϑΥʔϚϯεΛௐࠪ͢Δ
    /FX.FNPSZ.BOBHFS'FBUVSFT

    View full-size slide

  65. IUUQTLPUMJOMBOHPSHEPDTOBUJWFNFNPSZNBOBHFSIUN
    ɾ(SBEMFͷϑϥά 9SVOUJNFMPHTHDJOGP
    Ͱ($ͷϩάΛग़͢͜ͱ͕Ͱ͖Δ
    ɾύϑΥʔϚϯεௐࠪʹಛԽͨ͠ϩάͰ͸ͳ͍
    ,PUMJOd
    ($ͷύϑΥʔϚϯεΛௐࠪ͢Δ
    /FX.FNPSZ.BOBHFS'FBUVSFT

    View full-size slide

  66. IUUQTLPUMJOMBOHPSHEPDTOBUJWFJPTJOUFHSBUJPOIUNMTVQQPSUGPSCBDLHSPVOETUBUFBOEBQQFYUFOTJPOT
    ɾσϑΥϧτͰ͸ΞϓϦέʔγϣϯͷঢ়ଶʹґͬͯɺ.FNPSZ.BOBHFSͷৼΔ
    ෣͍͸มΘΒͳ͍
    ɾසൟʹ($Λಈ͔ͨ͘͠ͳ͍έʔεͰɺϝϞϦ࢖༻ྔ͕ඇৗʹଟ͍͚࣌ͩ($͕
    ಈ͘Α͏ʹͰ͖Δ
    HSBEMFQSPQFSUJFT
    kotlin.native.binary.appStateTracking=enabled
    ,PUMJOd
    J04ͷόοΫάϥ΢ϯυঢ়ଶͱ"QQ&YUFOTJPOTͱͷ࿈ܞ
    /FX.FNPSZ.BOBHFS'FBUVSFT

    View full-size slide

  67. IUUQTLPUMJOMBOHPSHEPDTOBUJWFNFNPSZNBOBHFSIUNM

    View full-size slide

  68. )BWFBOJDF,PUMJO

    View full-size slide