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

APIのデータのマッピングを 約18倍速くした話

magiepooh
February 22, 2018

APIのデータのマッピングを 約18倍速くした話

magiepooh

February 22, 2018
Tweet

More Decks by magiepooh

Other Decks in Technology

Transcript

  1. APIͷσʔλͷϚοϐϯάΛ
    ໿18ഒ଎ͨ͘͠࿩
    potatotips #48
    @magie_pooh

    View full-size slide

  2. ࣗݾ঺հ
    ౻ాୖຏ
    @magie_pooh
    @magiepooh
    झຯɾಛٕ:

    ΫϥϑτϏʔϧɾ೔ຊञɾϚδοΫɾ࠵຾

    View full-size slide

  3. ͱ͋ΔΞϓϦͷ։ൃத
    • ը໘ભҠ͕஗͍୺຤͕͋Δͳʔͱࢥͬͨ

    View full-size slide

  4. ͱ͋ΔΞϓϦͷ։ൃத
    • ը໘ભҠ͕஗͍୺຤͕͋Δͳʔͱࢥͬͨ
    • Nexus5Xͱ͔Ͱ਺ඵ

    View full-size slide

  5. ͱ͋ΔΞϓϦͷ։ൃத
    • ը໘ભҠ͕஗͍୺຤͕͋Δͳʔͱࢥͬͨ
    • Nexus5Xͱ͔Ͱ਺ඵ
    • SO-04G (5.0.2)Ͱը໘ભҠʹ20sec͘Β͍ɾɾ

    View full-size slide

  6. ঢ়گ
    • Wi-Fi઀ଓ؀ڥ
    • σʔλ͸JSONܗࣜ
    • αΠζ͸1MB
    • Kotlin + Moshi(=A modern JSON library for
    Android and Java)

    View full-size slide

  7. ରࡦ1ɿMoshi͕ѱ͍ͷͰ͸ʁ
    • moshi(moshi-kotlin: Square੡JSONύʔα)͸ϦϑϨΫγϣϯ
    Λ༻͍͍ͯΔͨΊɺίετ͕ߴ͍
    • KotshiΛ࢖͏
    • An annotations processor that generates Moshi adapters
    from immutable Kotlin data classes.
    • https://github.com/ansman/kotshi

    View full-size slide

  8. ରࡦ1ɿMoshi͕ѱ͍ͷͰ͸ʁ
    • moshi(moshi-kotlin: Square੡JSONύʔα)͸ϦϑϨΫγϣϯ
    Λ༻͍͍ͯΔͨΊɺίετ͕ߴ͍
    • KotshiΛ࢖͏
    • An annotations processor that generates Moshi adapters
    from immutable Kotlin data classes.
    • https://github.com/ansman/kotshi
    => 20sec -> 12sec

    View full-size slide

  9. ରࡦ2ɿΦϒδΣΫτੜ੒͕ଟ͗͢Δ໰୊
    • ഑ྻͷதʹΦϒδΣΫτ͕େྔʹଘࡏ͍ͯͨ͠
    {
    “hogeArray”: [
    {“obj”: {123, 456.2}},…
    ]
    }

    View full-size slide

  10. ରࡦ2ɿΦϒδΣΫτੜ੒͕ଟ͗͢Δ໰୊
    • ഑ྻͷதʹΦϒδΣΫτ͕େྔʹଘࡏ͍ͯͨ͠
    => ΦϒδΣΫτ͡Όͳ͘ɺStringܕͷ഑ྻͷ഑ྻͰදݱ͢Δ
    {
    “hogeArray”: [
    {“obj”: {123, 456.2}},…
    ]
    }
    {
    “hogeArray”: [
    [“123”, “456.2”],…
    ]
    }

    View full-size slide

  11. ରࡦ2ɿΦϒδΣΫτੜ੒͕ଟ͗͢Δ໰୊
    • ഑ྻͷதʹΦϒδΣΫτ͕େྔʹଘࡏ͍ͯͨ͠
    => ΦϒδΣΫτ͡Όͳ͘ɺStringܕͷ഑ྻͷ഑ྻͰදݱ͢Δ
    {
    “hogeArray”: [
    {“obj”: {123, 456.2}},…
    ]
    }
    {
    “hogeArray”: [
    [“123”, “456.2”],…
    ]
    }
    => 12sec -> 8.4secʢ഑ྻσʔλ͕ͦ΋ͦ΋ڊ
    େͩͬͨͨΊɺ͔ͳΓ͕ࠩग़ͨʣ

    View full-size slide

  12. ରࡦ3: APIఆٛΛݟ௚͢
    • ഑ྻσʔλΛ̍ͭʹڞ௨ԽͰ͖Δɾɾɾʂ
    • ॏෳͨ͠഑ྻσʔλΛ4ͭड͚औ͍ͬͯͨ
    => 8.4sec -> 2.9sec

    View full-size slide

  13. ·ͱΊ1
    • ΄΅Kotshiͷ͓͔͕͛ͩɺ20sec -> 2.9secʹͳͬͨ
    • େྔͷ഑ྻσʔλʹܕΛ͚ͭΔͷ͸Α͘ͳ͍
    • ʮͦͷ೔ɺਓྨ͸ࢥ͍ग़ͨ͠ɻ୺຤ؒͷύϑΥʔϚϯεࠩҟ
    ͷڪාΛɻͦΕͰ΋αϙʔτ͠ͳ͚Ε͹͍͚ͳ͍۶ৱΛɻʯ
    • SO-04G (5.0.2): ໿ 2.9sec
    • SO-02G (4.4.4): ໿ 0.64sec

    View full-size slide

  14. ·ͱΊ2
    • iOSͰ͸ͦ͜·Ͱύʔεʹ͕͔͔࣌ؒͬͯͳ͔ͬͨͷ͕ٙ໰
    • ΋͔ͯ͠͠ݹ͍୺຤ͩͱ͕͔͔࣌ؒΔʁ
    • ը໘ભҠΞχϝʔγϣϯ(Shared Element Transition)͕͋Δͱɺ
    2.9secͰ΋஗͘ײ͡ͳ͍
    • ͦΕͰ΋ɺ2.9sec͔͔Δͷ͕ݏͩͬͨͷͰɺେྔͷ഑ྻͷऔಘ͸
    ผAPIʹ੾Γग़ͨ͠ɻʢͦΕͰ1.2sec͘Β͍·ͰॖΊͯ18ഒͷύ
    ϑΥʔϚϯεվળୡ੒ɾɾʣ

    View full-size slide