google dev fest 2016 - realm database

31
Pham Khac [email protected] Build better apps, faster with Realm

Upload: pham-khac

Post on 08-Feb-2017

143 views

Category:

Mobile


1 download

TRANSCRIPT

Pham Khac [email protected]

Build better apps, faster with Realm

Realm

Mobile Database

Mobile Platform

Fast queriesOffline-first SecureCross platform

Benefits

safe threading

reactive architecture

community support

simplify

sync seamlessly

open sourceData push

browsable

auto migration

Trusted by Fortune 500 mainstays, innovative startups, and #1‑ranked app store successes,

Realm is built into apps used by hundreds of millions of people every day.

Over 1 billion users rely on Realm

Top apps are using Realm

Dubsmash Social Video, TV 1 - 5 M

Expensify Finance 1 - 5 M

Falcon Pro 3 Social 100 - 500 K

Tastely Food restaurant 10 - 50 M

Cabify Map-Navigation 1 - 5 M

Shyp Shipping 10 - 50 K

FiveStars Discover places 500K - 1M

8fit Health & Fitness 1 – 5 M

6

6

Benchmarking

Realm vs Sqlite

https://github.com/khacpv/realm-test

https://github.com/khacpv/realm-test

https://github.com/khacpv/Realm-DataStoreBenchMark

Speedup Realm vs SQLite

Realm vs SnappyDB

https://github.com/khacpv/DatabaseTester

Realm vs SnappyDB

CREATE READ DELETE

Nexus 5, 6.0.1

13

13

Why realm is fast?

• C++ core

• B+ trees

• Bit-packing

• Column-oriented

• Memory-mapped files

Cross-platform

Queries > writes (no-sql)

Smaller file size

Faster reads and writes

Zero-copy

https://realm.io/news/threading-deep-dive

Why realm is fast?

B+ TreeThe 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 …)

https://en.wikipedia.org/wiki/B+_tree

Bit-packingEfficient technique to store blocks of small integers

• 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

http://lemire.me/blog/2012/03/06/how-fast-is-bit-packing http://www.slideshare.net/jpountz/how-does-lucene-store-your-data

Column Oriented

http://arxiv.org/pdf/1105.4252.pdf

Memory mapped files

File

Stack

Heap

Data

Text

Mapped filePointer

https://msdn.microsoft.com/en-us/library/ms810613.aspx

19

19

How to play with Realm?

How to get Realm?

Web:

Version:

Support:

Stars:

https://realm.io

2.2.1 (Java - Android)

xamarin, java, obj-c, swift, react-native, javascript

6,525 (java), 9356 (cocoa)

classpath "io.realm:realm-gradle-plugin:2.2.1"

apply plugin: 'realm-android'

ProGuard!

Sync seamlessly

auto-updated

QueriesequalTo

greaterThan

between

contains

beginWith

beginGroup

or

not

isEmpty

distinct

sum/ count

min/ max/ average

findAll/ findFirst

sort

Insert / Update

Update managed object

Insert managed object

Delete

Delete single object

Delete many objects

25

25

Realm browser

Realm Browser

27

27

Realm mobile platform

Realm mobile data platform

Realm.io github.com/realm

Want to learn more? How it works & Getting started: realm.io/docs

Platforms: Java: github.com/realm/realm-java iOS: github.com/realm/realm-cocoa Javascript: github.com/realm/realm-js Xamarin: github.com/realm/realm-dotnet C++: github.com/realm/realm-core Server: github.com/realm/realm-mobile-platform

What's Next

30

30

Questions?

Thanks and have fun!

Pham Khac [email protected]