View
1.401
Download
3
Category
Preview:
DESCRIPTION
#MBLTdev: Конференция мобильных разработчиков Спикер: Brian Munkholm VP Engineering, Realm http://mbltdev.ru/
Citation preview
Realm and Lessons Learned building it
{MBLT}DEV ‘14
Brian Munkholm, VP Engineering @realm bm@realm.io @brianMunkholm
Menu:What is Realm? How popular? Why use Realm? Feedback Design goals & fulfilment - API examples Lessons Learned The future
What is Realm? • Modern mobile database - replace SQLite+ORMs • Easy: Object-oriented, but not an ORM • Safe: full ACID properties • Cross-platform: C++ core (3 years dev) • Small: compact data, object == DB (no copy!) • Fast • Free: open source!
Realm for iOS Used by >20,000 developers worldwide in < 8 weeks!
Including ~1,000 in or very close to production
>2200 GitHub Stars!
(Parse: 10k in 8 mon)
Realm for Android - launched 1 month ago Used by >5,000 developers worldwide the 1’st week!
First apps in production
>700 GitHub Stars in 2 weeks (GreenDao has 1592, ORMlite 307 after years!)
Why use Realm? - ask the devs!
Cloth
a beautifully designed personal outfit diary
>350k users
Uses Realm for all data handling
took over a 2 year-old codebase and ported it to Realm in 1 day.
clothapp.com reallyseth.com
Beanflow
Full POS & inventory app (w/ offline mode)
Uses Realm as network cache for all data
“I don't have any plans to go back to Core Data anytime soon. I really like Realm.”
sebastiandobrincu.com www.beanflow.com
Common benefits • Save time - save $$$ • Make faster & better apps • Uses less memory and disk • Free (de)serialisation • cross platform (iOS, Android, ++) • cross language
Design Goals
1. Simple
2. Fast 3. Modern
to learnto maintainto use across threads
1. Simple
public class Dog extends RealmObject { // Fields private String name; private int age; // + Getters and Setters… }
Models
// Obtain a Realm instance in each thread Realm realm = Realm.getInstance(this);
// ACID transactions give you easy thread-safety realm.beginTransaction();
Dog dog = realm.createObject(Dog.class); dog.setName("Rex"); dog.setAge(3);
// Full commit to disk (or memory) realm.commitTransaction();
Writes
RealmResults<User> teens = realm.where(User.class) .between("age", 13, 20) .findAll();
Queries
// Queries can be chained efficiently RealmResults<User> johns = teens.where() .equalTo("name", “John") .or() .contains("name", “Jo") .findAll();
public class Person extends RealmObject { private String name; private Dog bestDog; // One-One relations private RealmList<Dog> dogs; // One-Many relations … } realm.beginTransaction();
Person person = realm.createObject(Person.class); person.setName("Tim"); person.getDogs().add(dog);
realm.commitTransaction();
Relationships
new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void… voids) {
Realm realm = Realm.getInstance(this); realm.beginTransaction(); Person person = realm.createObject(Person.class); person.setName("Tim"); realm.commitTransaction();
return null; } }.execute();
Thread-safety: All access is the same
• Writes cannot conflict - they block
• No need to merge data sources, ever.
• Reads are consistent as soon as the write completes
Thread-safety:
2. Fast
BIG disclaimer! Use benchmarks as rough indicator Measure your own senarios
Lessons Learned
Lesson one
Aim high! • Worlds best product • Solid funding from the best • 100% dedicated team
Lesson two
Listen to the users / community • Ask users actively • Listen, understand their needs
and react quickly • It takes time!
Lesson three
Performance is great - but usability is king! • and eats performance… • Android/Java reflection is SLOW • but dont’ give up
Add a new object first time
• Runtime code generation • Use lower level APIs • Compile-time code
generation • Cache all the introspection
calls
0
25
50
75
100
Runtime Runtime+ Compile Time Cache
4 sec!!!
The future: • Encryption • Handover results between threads • Dynamic API / Migration • Advanced Query • Synchronisation • What do you want for xmas?
Watch or Influence?
Feedback : realm.io bm@realm.io #Realm #BrianMunkholm
Thanks for your support!!!
Recommended