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

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

F958fbf402a67a1742335a4894e041e5?s=47 magiepooh
February 22, 2018

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

F958fbf402a67a1742335a4894e041e5?s=128

magiepooh

February 22, 2018
Tweet

Transcript

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

  2. ࣗݾ঺հ ౻ాୖຏ @magie_pooh @magiepooh झຯɾಛٕ:
 ΫϥϑτϏʔϧɾ೔ຊञɾϚδοΫɾ࠵຾

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

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

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

  6. None
  7. ঢ়گ • Wi-Fi઀ଓ؀ڥ • σʔλ͸JSONܗࣜ • αΠζ͸1MB • Kotlin +

    Moshi(=A modern JSON library for Android and Java)
  8. ରࡦ

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

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

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

    456.2}},… ] } { “hogeArray”: [ [“123”, “456.2”],… ] } => 12sec -> 8.4secʢ഑ྻσʔλ͕ͦ΋ͦ΋ڊ େͩͬͨͨΊɺ͔ͳΓ͕ࠩग़ͨʣ
  14. ରࡦ3: APIఆٛΛݟ௚͢ • ഑ྻσʔλΛ̍ͭʹڞ௨ԽͰ͖Δɾɾɾʂ • ॏෳͨ͠഑ྻσʔλΛ4ͭड͚औ͍ͬͯͨ => 8.4sec -> 2.9sec

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

    • SO-04G (5.0.2): ໿ 2.9sec • SO-02G (4.4.4): ໿ 0.64sec
  16. ·ͱΊ2 • iOSͰ͸ͦ͜·Ͱύʔεʹ͕͔͔࣌ؒͬͯͳ͔ͬͨͷ͕ٙ໰ • ΋͔ͯ͠͠ݹ͍୺຤ͩͱ͕͔͔࣌ؒΔʁ • ը໘ભҠΞχϝʔγϣϯ(Shared Element Transition)͕͋Δͱɺ 2.9secͰ΋஗͘ײ͡ͳ͍

    • ͦΕͰ΋ɺ2.9sec͔͔Δͷ͕ݏͩͬͨͷͰɺେྔͷ഑ྻͷऔಘ͸ ผAPIʹ੾Γग़ͨ͠ɻʢͦΕͰ1.2sec͘Β͍·ͰॖΊͯ18ഒͷύ ϑΥʔϚϯεվળୡ੒ɾɾʣ