Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is reading fields of a Realm object being slower than java objects?

I'm thinking of using Realm.io as my ORM in production app.

As I understand from the docs RealmResults objects are stored in the BackendStore (disk) instead of on the RAM, as RealmResult is only a proxy of the real objects saved in the database.

So my question is, will reading the fields of a RealmObject being as quick as reading it from a normal Java object, given that Java objects are stored on RAM. I have many readings in my app, and I'm afraid this is going to affect responsiveness.

like image 531
orelzion Avatar asked Nov 11 '15 10:11

orelzion


1 Answers

It depends on what you're comparing with. The RealmResults is the result of a query, and Realm doesn't copy the objects - on the contrary to a traditional ORM. Realm will only fetch the object when needed while a typical ORM will copy the objects to memory. Copying the objects from SQLite to plain Java objects is bound by I/O performance.

Accessing a RealmObject might be slower than accessing a plain Java object. But a plain Java object isn't persistent. Realm offers an in-memory option, which is a more direct comparison with plain Java objects. In-memory Realms have the property as Plain objects: you loose the data when the app closes.

So if you are spending a lot of time copying objects from SQLite in order to have fast in-memory objects, it might end up being slower overall.

like image 79
geisshirt Avatar answered Oct 31 '22 22:10

geisshirt