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

【Ebisu.mobile#3】バイトルアプリへのSwift Concurrency導入とその効果

Cychow
July 05, 2023

【Ebisu.mobile#3】バイトルアプリへのSwift Concurrency導入とその効果

Cychow

July 05, 2023
Tweet

More Decks by Cychow

Other Decks in Programming

Transcript

  1. όΠτϧΞϓϦ΁ͷSwift Concurrency
    ಋೖͱͦͷޮՌ
    Eiji Shirakazu, iOS Engineer in dip

    View Slide

  2. ࣗݾ঺հ
    ന਺ ӥ࢘ / Eiji Shirakazu
    @cychow_app
    όΠτϧ iOSΞϓϦ։ൃ୲౰
    ࠷ۙ͸Vision Pro (visionOS)ͷγϛϡϨʔλͰ༡ΜͰ͍·͢ʂ

    View Slide

  3. View Slide

  4. ຊ೔ͷ಺༰
    όΠτϧΞϓϦͷ͝঺հͱ։ൃपΓͷ͓࿩
    ͦ΋ͦ΋Swift Concurrencyͱ͸
    Swift ConcurrencyΛͲͷΑ͏ʹಋೖ͔ͨ͠
    Swift Concurrencyಋೖޙͷঢ়گ

    View Slide

  5. όΠτϧΞϓϦͱ͸…
    ɾΞϧόΠτ/ύʔτٻਓݕࡧαʔϏε
    ɾ෯޿͍෼໺͔༷ͭʑͳ৚݅ͷΞϧόΠτ/ύʔτ৘ใɹ


    ɹΛ਺ଟ͘ܝࡌʂ
    ɾࣸਅ΍ಈըͳͲ͔ΒΞϧόΠτ/ύʔτઌͷ੍෰΍ಇ͍ͯ


    ɹ͍Δελοϑɺ৬৔ͷงғؾͳͲΛ֬ೝ͢Δ͜ͱ͕Ͱ͖Δʂ

    View Slide

  6. ʮॳճΠϯετʔϧޙͷମݧ޲্ʯػೳʹ͍ͭͯ
    εϓϥογϡ ٻਓͷҰཡ

    View Slide

  7. ʮॳճΠϯετʔϧޙͷମݧ޲্ʯػೳʹ͍ͭͯ
    εϓϥογϡ Ϣʔβʔ΁ͷ࣭໰

    View Slide

  8. ʮॳճΠϯετʔϧޙͷମݧ޲্ʯػೳͷ։ൃͰ


    Swift ConcurrencyΛಋೖʂʂ

    View Slide

  9. Swift Concurrencyͱ͸
    WWDC21ʹͯొ৔ͨ͠৽ͨͳฒߦॲཧͷख๏
    async/awaitΩʔϫʔυΛ༻͍Δ͜ͱͰඇಉظॲཧ / ฒߦॲཧΛ࣮ݱ͢Δ
    async/awaitҎ֎ʹ΋Actor΍TaskɺAsyncStreamͳͲͷ֓೦΋ొ৔

    View Slide

  10. View Slide

  11. View Slide

  12. Swift ConcurrencyΛͲͷΑ͏ʹಋೖ͔ͨ͠
    ᶃ ·ͣ͸ࣗ਎͕ੵۃతʹConcurrencyʹ͍ͭͯΠϯϓοτͨ͠
    ᶄ ಋೖ͢Δ͜ͱʹͲΕ͘Β͍ͷϝϦοτ͕͋Δ͔Λߟ࡯ͨ͠

    View Slide

  13. ɾඇಉظॲཧΛಉظॲཧͷΑ͏ʹදه͢Δ͜ͱͰ࣮ߦॱংΛ௥͍΍͍͢
    Swift ConcurrencyΛಋೖ͢ΔϝϦοτ
    ɾσʔλڝ߹Λճආ͠΍͘͢ͳΔ
    ɾiOS13Ҏ߱Ͱ࢖༻͢Δ͜ͱ͕Ͱ͖Δ
    ɾΤϥʔϋϯυϦϯάΛߦ͍΍͘͢ͳΔ
    ͳͲ…

    View Slide

  14. Swift ConcurrencyΛͲͷΑ͏ʹಋೖ͔ͨ͠
    ᶅ ઌഐΤϯδχΞͷํʑͱ૬ஊ͠ɺαʔϏεʹ༩͑ΔӨڹΛߟ্ྀͨ͠Ͱಋೖ


    ɹ͍ͯ͘͜͠ͱʹͨ͠
    ᶃ ·ͣ͸ࣗ਎͕ੵۃతʹConcurrencyʹ͍ͭͯΠϯϓοτͨ͠
    ᶄ ಋೖ͢Δ͜ͱʹͲΕ͘Β͍ͷϝϦοτ͕͋Δ͔Λߟ࡯ͨ͠
    ᶆ Өڹൣғ͕খ͍͞ʮॳճΠϯετʔϧޙͷମݧʯΛ޲্ͤ͞ΔϓϩδΣΫτ


    ɹʹͯಋೖ͢Δ͜ͱͱͨ͠

    View Slide

  15. ɾcompletionHandlerΛ༻͍ͣɺasync/awaitΛ༻͍ͯදه͢Δɻ
    ɾGCDΛ࢖༻͢ΔՕॴΛTaskʹஔ͖׵͑Δɻ
    ɾMainActorΛࢦఆ͢ΔՕॴʹ஫ҙ͢Δɻ
    Swift ConcurrencyΛಋೖ࣌ͷϙΠϯτ
    ɾwithCheckedContinuation΍withCheckedThrowingContinuationͰ


    ɹطଘͷඇಉظॲཧΛasync/awaitʹରԠͤ͞Δ͜ͱ͕Ͱ͖Δɻ
    ͳͲ

    View Slide

  16. ͨͩɺ໰୊఺΋…

    View Slide

  17. ௚໘ͨ͠໰୊఺
    ଞͷ։ൃνʔϜϝϯόʔ΍৽نࢀըऀͷํʹରͯ͠Concurrencyͷ
    ॻ͖ํͳͲΛ஌ͬͯ΋Β͏ඞཁ͕͋ͬͨɻ

    View Slide

  18. ໰୊఺ͷղܾࡦ
    LTେձ΁ࢀՃ

    View Slide

  19. Swift Concurrencyಋೖޙͷঢ়گ
    ɾιʔείʔυͷՄಡੑ͕޲্ͨ͠
    ɾνʔϜϝϯόʔ͕ੵۃతʹΩϟονΞοϓ͢ΔΑ͏ʹͳͬͨ
    ʲݱঢ়ʳ
    ɾαʔυύʔςΟ੡ϥΠϒϥϦ͔Βඪ४ϥΠϒϥϦʹҠߦ͢Δ͜ͱ͕Ͱ͖͍ͯΔ

    View Slide

  20. Swift Concurrencyಋೖޙͷঢ়گ
    ɾSwift6΁ͷϝδϟʔΞοϓσʔτͷ४උ
    ʲࠓޙͷ՝୊ʳ

    View Slide

  21. View Slide

  22. Swift Concurrencyಋೖޙͷঢ়گ
    ɾࠓޙͷSwift6΁ͷϝδϟʔΞοϓσʔτͷ४උ
    ɾίϯύΠϥϑϥάʮStrict Concurrency CheckingʯͷಋೖͳͲ΋ݕ౼
    ʲࠓޙʳ

    View Slide

  23. ίϯύΠϥϑϥάʮStrict Concurrency Checkingʯ

    View Slide

  24. ίϯύΠϥϑϥάʮExistentialAnyʯ΋ಋೖݕ౼த….

    View Slide

  25. Swift Concurrencyಋೖޙͷঢ়گ
    ɾࠓޙͷSwift6΁ͷϝδϟʔΞοϓσʔτͷ४උ
    ɾίϯύΠϥϑϥάʮStrict Concurrency CheckingʯͷಋೖͳͲ΋ݕ౼
    ɾSendable΁ͷ४ڌͷνΣοΫͳͲ΋͓͜ͳ͍͖͍ͬͯͨ
    ʲࠓޙʳ

    View Slide

  26. όΠτϧͰ͸Ҿ͖ଓ͖ٕज़త௅ઓΛଓ͚͍͖ͯ·͢ʂ

    View Slide

  27. View Slide