Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
1
X y
- Queries too slow
- Schemas change
- Complex relationships
- 3NF, BCNF…
- Nest SELECT, JOIN
- 1-n, 1-1, n-n
- Migra...
REALM
khacpv@gmail.com

15/05/2016
no-sqlite for mobile
Who am I?
3
Realm is
SQL
SELECT user.name, user.email
FROM user
INNER JOIN shop ON user.id = shop.userid

INNER JOIN city ON user.city...
Realm is
SQLite
SELECT user.name, user.email
FROM user
INNER JOIN shop ON user.id = shop.userid

INNER JOIN city ON user.c...
YOUR 

logo?
6
How: fastest?
7
Galaxy S4
8
Zenfone 5
9
Why: fastest?
10
Speed force
• Memory-mapped files
• C++ core
• B+ trees
• Column-oriented
• Bit-packing
Minimize I/O overhead

Cross-platfo...
benchmark vs SQLite
http://static.realm.io/downloads/java/android-benchmark.zip 12
Architecture
Realm Object Store API
Realm Internal API
JNI
Realm Core
13
Method count
• Realm: ~1750
• Model class: +2x no. of fields
• Proxy class: + 2x no. of fields + 11
• Total: "it depends" (~...
How: code?
15
get Realm
16
web:
version:
support:
contributors:
last release:
https://realm.io
0.90.1
xamarin, java, obj-c, swift, react...
Realtime
17
update realtime
Types fields
18
@Required
@Ignore
@RealmClass
@Index
@PrimaryKey
boolean
byte, short,int,long -> long
float
double
String
Da...
Relationships
19
n…1
n…n
Queries
20
• equalTo
• greaterThan
• between
• contains
• beginWith
• beginGroup
• or
• not
• isEmpty
• distinct
• sum/ co...
Insert / Update
21
Delete
22
Configuration
23
1. Encrypt with key (AES-256)
2. Migration strategy
3. In memory mode
4. Default instance
5. isAutoRefresh...
Thread
Realm
Realm
object
Realm
Results
Threads
24
RealmObject
A B C
Not yet Polymorphism
Debug
25
Crashlytics
Limitations
26
1. Class names: <= 57 letters*
2. Field names: <= 63 letters
3. Nest transactions -> not supported!
4. Stri...
References
• https://realm.io/news/introducing-realm
• https://realm.io/users/chatwork
• https://github.com/realm
• http:/...
Q & A
28
• Why do you choose Realm?
• Faster 5~10 times, especialy in write data
• Combine with ActiveAndroid
• Which data should b...
30
Appendix
B+ Tree
31https://en.wikipedia.org/wiki/B%2B_tree
The primary value of a B+ tree is in storing data for
efficient retrieval...
Column Oriented
32http://arxiv.org/pdf/1105.4252.pdf
Memory-mapped
33
Memory-mapped I/O uses the same address bus to
address both memory and I/O devices
CPU
RAM
Hard Disk
I/O
...
http://www.slideshare.net/jpountz/how-does-lucene-store-your-data
http://lemire.me/blog/2012/03/06/how-fast-is-bit-packing...
Próxima SlideShare
Cargando en…5
×

Realm Presentation

2.185 visualizaciones

Publicado el

Framgia Presentation: No-sql for Android with Realm

Publicado en: Tecnología
  • Justin Sinclair has helped thousands of menget their Ex girlfriends back using his methods. Learn them at here◆◆◆ http://goo.gl/FXTq7P
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí

Realm Presentation

  1. 1. 1 X y - Queries too slow - Schemas change - Complex relationships - 3NF, BCNF… - Nest SELECT, JOIN - 1-n, 1-1, n-n - Migration - Synchonize - Huge records - … SQLite problems
  2. 2. REALM khacpv@gmail.com
 15/05/2016 no-sqlite for mobile
  3. 3. Who am I? 3
  4. 4. Realm is SQL SELECT user.name, user.email FROM user INNER JOIN shop ON user.id = shop.userid
 INNER JOIN city ON user.cityid = city.id WHERE user.name = 'the flash' No-SQL Realm.getA().getC().getF(); A B C D E F G X Z y 4
  5. 5. Realm is SQLite SELECT user.name, user.email FROM user INNER JOIN shop ON user.id = shop.userid
 INNER JOIN city ON user.cityid = city.id WHERE user.name = 'khac' No-SQLite Realm.getA().getC().getF(); A B C D E F G X Z y 5
  6. 6. YOUR 
 logo? 6
  7. 7. How: fastest? 7
  8. 8. Galaxy S4 8
  9. 9. Zenfone 5 9
  10. 10. Why: fastest? 10
  11. 11. Speed force • Memory-mapped files • C++ core • B+ trees • Column-oriented • Bit-packing Minimize I/O overhead
 Cross-platform
 Faster reads and writes
 Queries > writes (no-sql)
 Smaller file size 11
  12. 12. benchmark vs SQLite http://static.realm.io/downloads/java/android-benchmark.zip 12
  13. 13. Architecture Realm Object Store API Realm Internal API JNI Realm Core 13
  14. 14. Method count • Realm: ~1750 • Model class: +2x no. of fields • Proxy class: + 2x no. of fields + 11 • Total: "it depends" (~2000) Picasso: ~600
 GSON: ~950
 RxJava: ~3500 Retrofit: ~494 Support Lib: ~12300
 OrmLite: ~2400 14
  15. 15. How: code? 15
  16. 16. get Realm 16 web: version: support: contributors: last release: https://realm.io 0.90.1 xamarin, java, obj-c, swift, react-native 52+ (java) 7 days ago (13/05/2016) classpath "io.realm:realm-gradle-plugin:0.90.1" apply plugin: 'realm-android' ProGuard!
  17. 17. Realtime 17 update realtime
  18. 18. Types fields 18 @Required @Ignore @RealmClass @Index @PrimaryKey boolean byte, short,int,long -> long float double String Date byte[] final transient volatile
  19. 19. Relationships 19 n…1 n…n
  20. 20. Queries 20 • equalTo • greaterThan • between • contains • beginWith • beginGroup • or • not • isEmpty • distinct • sum/ count • min/ max/ average • findAll/ findFirst • sort • …
  21. 21. Insert / Update 21
  22. 22. Delete 22
  23. 23. Configuration 23 1. Encrypt with key (AES-256) 2. Migration strategy 3. In memory mode 4. Default instance 5. isAutoRefresh() & waitForChange() 6. Create from JSON https://nelenkov.blogspot.dk/2012/05/storing-application-secrets-in-androids.html https://developer.android.com/training/articles/keystore.html
  24. 24. Thread Realm Realm object Realm Results Threads 24 RealmObject A B C Not yet Polymorphism
  25. 25. Debug 25 Crashlytics
  26. 26. Limitations 26 1. Class names: <= 57 letters* 2. Field names: <= 63 letters 3. Nest transactions -> not supported! 4. String & byte[] < 16Mb *Realm auto append class_ at begin of class name
  27. 27. References • https://realm.io/news/introducing-realm • https://realm.io/users/chatwork • https://github.com/realm • http://www.slideshare.net/ChristianMelchior/realm-building-a- mobile-database • http://www.slideshare.net/dalinaum/realm-java • https://en.wikipedia.org/wiki/Zero-copy • https://en.wikipedia.org/wiki/Data_structure_alignment 27
  28. 28. Q & A 28
  29. 29. • Why do you choose Realm? • Faster 5~10 times, especialy in write data • Combine with ActiveAndroid • Which data should be stored in Realm? • The data need to be writen many times, ex: total chats. • Should remove ActiveAndroid to only play with Realm. • Yes, it’s doesn’t complicated but ActiveAndroid has value too. • Easy to synchronize with data from server • Yes, no problem • Use for both Android & Ios? • Yes 29 ChatWork Ryutaro Miyashita https://realm.io/users/chatwork/
  30. 30. 30 Appendix
  31. 31. B+ Tree 31https://en.wikipedia.org/wiki/B%2B_tree The primary value of a B+ tree is in storing data for efficient retrieval in a block-oriented storage context in particular, filesystems. (NTFS, EXT4, SQLite, Oracle …
  32. 32. Column Oriented 32http://arxiv.org/pdf/1105.4252.pdf
  33. 33. Memory-mapped 33 Memory-mapped I/O uses the same address bus to address both memory and I/O devices CPU RAM Hard Disk I/O https://en.wikipedia.org/wiki/Memory-mapped_file
  34. 34. http://www.slideshare.net/jpountz/how-does-lucene-store-your-data http://lemire.me/blog/2012/03/06/how-fast-is-bit-packing/ Bit-packing 34 • Efficient technique to store blocks of small ints • Supports random access • Special case: bits per value = 1 is a bit set • Say you want to store • 5 30 1 1 10 12 • Raw data: 6 * 32 = 192 bits • Packed : 6 * 5 = 30 bits (84% size reduction!) 0000 0000 0000 0000 0000 0000 0000 0101 = 5 0000 0000 0000 0000 0000 0000 0001 1110 = 30 0000 0000 0000 0000 0000 0000 0000 0001 = 1 0000 0000 0000 0000 0000 0000 0000 0001 = 1 0000 0000 0000 0000 0000 0000 0000 1010 = 10 0000 0000 0000 0000 0000 0000 0000 1100 = 12

×