Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Realmの処理を再利用可能かつ合成可能にする
Search
ukitaka
June 10, 2017
Programming
0
870
Realmの処理を再利用可能かつ合成可能にする
https://github.com/ukitaka/RealmIO
の解説
ukitaka
June 10, 2017
Tweet
Share
More Decks by ukitaka
See All by ukitaka
CSの生産性改善を支える分析環境 Mercari CS/CRE Tech Talk #1
ukitaka
1
2.6k
switchのexhaustiveness/redundancy チェック 理論と実装 わいわいswiftc #8 @ukitaka
ukitaka
0
180
SwiftのDemanglerを書く @ わいわいswiftc番外編
ukitaka
0
410
Swiftの型システムに入門する - iOSDC Japan 2018
ukitaka
10
4.7k
Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift
ukitaka
6
1.3k
理論から入門するswift/lib/Sema - わいわいswiftc #1
ukitaka
5
1.5k
マルチスレッドRxSwift @ 社内RxSwift勉強会
ukitaka
5
1.1k
今日こそ理解するHot / Cold @社内RxSwift勉強会
ukitaka
14
2.6k
RxSwift コードリーディングの勘所@社内RxSwift勉強会
ukitaka
3
970
Other Decks in Programming
See All in Programming
サーバーレスで負荷試験!Step Functions + Lambdaを使ったk6の分散実行
shuntakahashi
6
1.6k
The Sequel to a Dream of Ruby Parser's Grammar
ydah
1
220
ECMAScript、Web標準の型はどう管理されているか / How ECMAScript and Web standards types are maintained
petamoriken
3
390
RAGの回答精度評価用のQAデータセットを生成AIに作らせた話
kurahara
0
250
Our Websites Need a Lifestyle Change, Not a Diet
ryantownsend
0
150
全部見せます! クラシルリワードのSwiftTesting移行プロジェクト
uetyo
0
210
API Platform for Laravel
dunglas
0
320
2024 컴포즈 정원사
jisungbin
0
150
LangChainの現在とv0.3にむけて
os1ma
4
920
Crafting Cross-Platform Adventures: Building a Game Engine with Kotlin Multiplatform
dwursteisen
0
120
connect-go で面倒くささと戦う / 2024-08-27 #newmo_layerx_go
izumin5210
2
650
Method Swizzlingを行うライブラリにおけるマルチモジュール設計
yoshikma
0
120
Featured
See All Featured
The Invisible Side of Design
smashingmag
296
50k
Pencils Down: Stop Designing & Start Developing
hursman
119
11k
KATA
mclloyd
27
13k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
1
53
The Straight Up "How To Draw Better" Workshop
denniskardys
230
130k
How to name files
jennybc
75
98k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
24
610
Clear Off the Table
cherdarchuk
91
320k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
No one is an island. Learnings from fostering a developers community.
thoeni
18
2.9k
A Tale of Four Properties
chriscoyier
155
22k
Transcript
RealmͷॲཧΛ࠶ར༻Մೳ ͔ͭ߹Մೳʹ͢Δ @ukitaka
ಥવͰ͕͢Έͳ͞Μ
RealmͷॲཧΛ͢ΔؔΛ Ͳ͏ॻ͍͍ͯ·͔͢
ྫ͑͜͏
ྫ͑͜͏ RealmͷΠϯελϯεதͰੜ͢Δ
ྫ͑͜͏ τϥϯβΫγϣϯΛ࣮ߦ͢Δ
ྑͦ͞͏ʁ
͍͔͕ͭ͋͘Δ
Կ͕͔
Կ͕͔ ͦΕͧΕͰτϥϯβΫγϣϯ͕࣮ߦ͞Εͯ͠·͏
τϥϯβΫγϣϯ • ݺͼग़͠ͷͨͼʹɺॲཧ͕࣮ߦ͞Εͯ͠·͏ ͷͰɺ1ͭͷτϥϯβΫγϣϯʹ·ͱΊΒΕͳ ͍ɻॲཧΛAtomicʹͰ͖ͳ͍ɻ • ॲཧͷهड़ͱ࣮ࡍͷ࣮ߦ͕Ͱ͖͍ͯͳ͍ɻ
τϥϯβΫγϣϯ • RealmʹݶΒͣɺҰൠతʹτϥϯβΫγϣϯͷ ։࢝ॏ͍ॲཧ • ຖճੜ͢Δͷͱ1ͭͷτϥϯβΫγϣϯʹ· ͱΊΔͷͰ(खݩͰܭଌͨ͠ͱ͜Ζ)10ഒҧ͏
ͭ·Γɺ͜ͷ··Ͱ
࠶ར༻͠ʹ͍͘ʂ
None
Ͳ͏͢Δʁ
ෳ༻ͷؔΛผʹ࡞Δʁ
͡Ό͋͜Ε…ʁ
͜ΜͳؔΛຖճ࡞Δͷʁ
߹Ͱ͖ΔΑ͏ʹ͍ͨ͠ʂ
None
τϥϯβΫγϣϯͷ։࢝Λ ͏ଆͰΒͤͯΈΔ
None
None
࠶ར༻ͨ͠Γɺ Έ߹ΘͤͨΓ
1ͭͷτϥϯβΫγϣϯΛ ΈཱͯΔ͜ͱ͕Ͱ͖ΔΑ͏ ʹͳͬͨʂ
࣮ࡍDDDຊͳͲʹͦ͏͠Ζͱ ॻ͍ͯ͋Δ ʮΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭʯ ΑΓ
ྑͦ͞͏ʁ
͍͔͕ͭ͋͘Δ
Կ͕͔ • τϥϯβΫγϣϯͷ੍ޚͷݺͼग़͠ଆ ʹ͋Δ͕ɺͦͷ͜ͱΛڧ੍Ͱ͖ͳ͍ɻͭ·Γ ։࢝͠ΕͳͲΛίϯύΠϧ࣌ʹݕग़Ͱ͖ͳ ͍ɻ • γάωνϟΈ͚ͨͩͰτϥϯβΫγϣϯͷ ։͕࢝ඞཁͳͷ͔Ͳ͏͔Θ͔Βͳ͍ɻ
Կ͕͔ τϥϯβΫγϣϯΛ։͖࢝͢ʁ ࣮Կ͔ॻ͖ࠐΜͰ͍ͨΓ͠ͳ͍ʁ (ಡΈࠐΈΛͯ͠ɺͳ͚Ε৽ن࡞ͱ͔)
None
Կ͕͔ • ຖճҾͰ͢ͷͪΐͬͱΊΜͲ͍͘͞ • σϑΥϧτઃఆͷRealmΛ͏ͱ͍͏҉ͷ ྃղ͕͋Εͣ͞ʹதͰੜͯ͠ྑ͍ ͕…
None
ཧ: Ͳ͏ͳ͍ͬͯΕཧ͔ • ॲཧͷ༰Λఆٛͭͭ͠ɺͦΕͧΕΛ߹Ͱ͖Δ Α͏ʹ͍ͨ͠ɻͭ·ΓτϥϯβΫγϣϯΛΈཱ ͯΔλΠϛϯάͱ࣮ߦͷλΠϛϯάΛ͚͍ͨɻ • τϥϯβΫγϣϯͷ։͕࢝ඞཁͰ͋Δ͜ͱΛ໌ࣔ తɺ੩తʹදݱ͍ͨ͠ɻ •
Ͱ͖Ε͍׳ΕͨI/FͰɺ؆ܿʹॻ͖͍ͨ
ཧ: Ͳ͏ͳ͍ͬͯΕཧ͔ • ॲཧͷ༰Λఆٛͭͭ͠ɺͦΕͧΕΛ߹Ͱ͖Δ Α͏ʹ͍ͨ͠ɻͭ·ΓτϥϯβΫγϣϯΛΈཱ ͯΔλΠϛϯάͱ࣮ߦͷλΠϛϯάΛ͚͍ͨɻ • τϥϯβΫγϣϯͷ։͕࢝ඞཁͰ͋Δ͜ͱΛ໌ࣔ తɺ੩తʹදݱ͍ͨ͠ɻ •
Ͱ͖Ε͍׳ΕͨI/FͰɺ؆ܿʹॻ͖͍ͨ
ΒͲ͔͜Ͱಉ͡Α͏ͳ ͜ͱΛ͍ͬͯΔͷΛ ࣮ݟͨ͜ͱ͕͋Δ
None
None
͜Ε͋Εͩ…
※ۤखͳํͷͨΊʹϞβΠΫॲཧΛࢪ͍ͯ͠·͢
ʮScalaؔܕσβΠϯ&ϓϩάϥϛϯάʯ ΑΓ
ؔܕϓϩάϥϛϯάͷྗΛ आΓΔ
࡞ͬͨ
RealmIO https://github.com/ukitaka/RealmIO
Ͳ͏࡞͔ͬͨʁ
͜ΕΛ
͜͏͡Ό
͜͏͡Ό CurryԽ͢Δͱڞ௨ͷύλʔϯ͕ݟ͑Δ
None
ͯ͢ͷRealmͷॲཧ͜͏දͤΔ ※ʮRealmΛड͚औͬͯԿ͔Λͯ݁͠ՌΛฦ͢ʯΈ͍ͨͳײ͡Ͱ͢ɻ ※ErrorॲཧҰ୴ߟ͑ͯ·ͤΜ
͞Βʹ͜ΕΛ
͜͏͡Ό
ͭ·Γ͜ΕΛ
͜͏͡Ό
͜ͷܕΛϕʔεʹਐΊΔ
͜͜·Ͱͷ·ͱΊ
ڞ௨෦͕͋ͬͨͷͰ͜͏͚ͨͩ͠
RealmIO<T>
RealmIO<T>
RealmIO<T>
RealmIO<T>
࣮ࡍͷίʔυͰErrorΛthrow Ͱ͖ΔΑ͏ʹͳ͍ͬͯΔ
ͳΜͱͳ͘ runΛݺͿ·Ͱ࣮ߦ͞Εͳ͍ ײ͡ग़͖ͯͨ
͕ɺ ·ͩͳʹղܾ͍ͯ͠ͳ͍
ͩΕτϥϯβΫγϣϯ ։࢝ͯ͠ͳ͘Ͷʁ
࡞Δ
τϥϯβΫγϣϯ੍ޚ
τϥϯβΫγϣϯ੍ޚ Realm͕RealmIOΛҾʹऔͬͯ
τϥϯβΫγϣϯ੍ޚ τϥϯβΫγϣϯ։࢝ͯ͠
τϥϯβΫγϣϯ੍ޚ ࣮ߦ !!!
τϥϯβΫγϣϯ੍ޚ • ͏ͱ͖realm.run(io:) ΛݺͿΑ͏ʹ͢Δ • io.runݺͳ͍Α͏ʹɺ࣮ࡍinternal ͳΓʹ͓ͯ͘͠ɻ
ͱ͜ΖͰRead͚ͩͷͱ͖ʁ
τϥϯβΫγϣϯ੍ޚ • ύϑΥʔϚϯεతʹɺແବʹτϥϯβΫ γϣϯΛ։͖࢝͢Ͱͳ͍ɻ • ಡΈࠐΈͷΈͷ߹τϥϯβΫγϣϯΛ։ ࢝͠ͳ͍Α͏ʹ͢ΔͨΊʹɺॲཧ͕Readͳͷ ͔Writeͳͷ͔Λผ͢ΔΈ͕ඞཁɻ
τϥϯβΫγϣϯ੍ޚ ܕใ͔ΒRead/Write͕ผͰ͖ͳ͍
࡞Δ
͜ΕΛ
͜͏͡Ό
͜͏͡Ό Read͔Write͔ΛܕύϥϝʔλͰද͢
ͭ·Γ͜ΕΛ
͜͏͡Ό
͜͏͡Ό Read͔Write͔Λද͢ܕύϥϝʔλ
͜͏͡Ό ฦΓͷܕΛද͢ܕύϥϝʔλ
τϥϯβΫγϣϯ੍ޚ
τϥϯβΫγϣϯ੍ޚ Writeͷ߹τϥϯβΫγϣϯΛ ։͔࢝ͯ͠ΒॲཧΛ࣮ߦ
τϥϯβΫγϣϯ੍ޚ Readͷ߹τϥϯβΫγϣϯΛ ։࢝ͤͣʹॲཧΛ࣮ߦ
Ͱ͖͖ͯͨ
࣮ࡍʹެ։͍ͯ͠Δίʔυͱ ΄΅͓ͳ͡
PhantomType ͪͳΈʹRWܕύϥϝʔλ PhantomType(༓ྶܕ)ͱ͍ͬͯɺRead / WriteΛද͚ͩ͢ͰɺͲͷϝιουͷγάω νϟʹݱΕͳ͍ɻ
͜͜·Ͱͷ·ͱΊ
None
flatMapͰ ߹Ͱ͖ΔΑ͏ʹ͢Δ
͍ํΠϝʔδ
͍ํΠϝʔδ
ͻͱ͕ͭ͋Δ
߹ͨ͠Β Read / Write Ͳ͏ͳΔʁ
Read / Write
Read / Write RWܕύϥϝʔλʹԠͯ͡ ෳͷflatMapͷ࣮͕ඞཁ
Read / Write
τϥϯβΫγϣϯ ͪΖΜrunͨ͠Β1ͭͷ τϥϯβΫγϣϯͰॲཧ͕ߦΘΕΔ
ʂ
ͪͳΈʹϥΠϒϥϦͰɺrealmͷ ϝιουͷRealmIO൛Λఏڙ
ᘳʁ
Ͱ͖ͳ͔ͬͨ͜ͱ • εϨουʹ͍ͭͯͳʹͰ͖ͳ͔ͬͨɻॲ ཧͷهड़ͱ࣮ߦΛ͍ͯ͠ΔͷͰɺͦͷ2ͭ ͕ผεϨουͰߦΘΕΔՄೳੑ͕͋ΔͷͰɺ ͦ͜ͷ҆શੑΛϥΠϒϥϦଆͰอূ͔ͨͬ͠ ͕ͨɺThreadSafeReferenceͷ੍ͰͰ͖ ͣɻ
Ͱ͖ͳ͔ͬͨ͜ͱ objectΛҾड͚औΔϝιουʹ͓͍ͯɺ ݺͼग़࣌͠ͷεϨουͱ
Ͱ͖ͳ͔ͬͨ͜ͱ realm.run(io:)Λݺͼग़͢εϨου͕ ҧ͏Մೳੑ͕͋Δɻ
Ͱ͖ͳ͔ͬͨ͜ͱ ඞཁͳΒTSRͰҾ͖࣮͢ΛೖΕΑ͏ͱ͕ͨ͠…
Ͱ͖ͳ͔ͬͨ͜ͱ ThreadSafeReferenceτϥϯβΫγϣϯͰ resolveͰ͖ͳ͍ͱ͍͏੍͕͋Δ
Ͱ͖ͳ͔ͬͨ͜ͱ ͜͜τϥϯβΫγϣϯͳͷͰ resolveͰ͖ͳ͍
Ͱ͖ͳ͔ͬͨ͜ͱ • ࣮ࡍʹେ͖ͳʹͳΔ͔ͱݴΘΕΔͱɺͦ ͜·ͰͰͳ͍(ͱߟ͍͑ͯΔ)ɻಉ͡εϨου Ͱrealm.run(io:)ΛݺͿ͔ɺobjectΛҾͰड ͚औΔϝιουflatMapͷதͰ͏Α͏ʹ͢ Εى͖ͳ͍ɻ
Ͱ͖ͳ͔ͬͨ͜ͱ • Stack overflowͷՄೳੑ͕ͳ͘ͳ͍ɻͰͦ Μͳʹ߹͢Δ͜ͱݱ࣮తʹͳ͍ͷͰɺ ΄ͱΜͲʹͳΒͳ͍ɻ • RxSwift͕Stack overflowى͜͢ͷͱಉ͘͡Β ͍ͷϦεΫ(΄΅ͳ͍)
Ͱ͖ͳ͔ͬͨ͜ͱ • ଞͷϞφυͱΈ߹ΘͤΔͷ(ݱࡏͷSwiftͰ )͍͠ɻྫ͑RxSwiftΛ͍ͬͯΔ߹ɺ ObservableͱRealmIOΛ͏·͘Έ߹ΘͤΔ ͷݫ͍͠ɻ • ͜Εߴ֊ଟ૬͕ͳ͍ͱݫ͍͕͠…Swiftʹ ೖΒͳͦ͞͏
ࢀߟ • ReaderϞφυ • Slick (ScalaͷDBϥΠϒϥϦ) • ΞΠσΟΞ͜ΕͷDBIOAction͔Β • υϫϯΰൿͷτϥϯβΫγϣϯϞφυΛղઆ
IUUQRJJUBDPNQBC@UFDIJUFNTFDEDGGB
RealmIO https://github.com/ukitaka/RealmIO