question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance - Overhead of using Realm objects

See original GitHub issue

Currently, using Realm in a scenario which require a lot of calls through the C++/JS boundary (i.e. in a tight loop), can totally kill the performance of an app.

We did some tests and for example, just accessing something like

results[0].myprop

was >200x slower with Realm objects than normal JS array of objects (which you’d get after running a query on other databases).

Some possible solutions:

  • Graal.js in theory could help with that, but it seems that node extensions are not optimized at this point

  • Automatic caching of retrieved data (datomic does something similar)

  • Using something like JSON.parse(JSON.stringify(results)) instead of realm collections and objects - slow and ugly, last-resort hack

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:30 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
l7xcommented, Apr 6, 2020

Yeah, I explained that in my reply to @cristianoccazinsp. This test is hitting the previously mentioned results[0].myprop access (which also reveals another issue which we noticed and you mentioned - if you access results[0] multiple times, why not return the same object (it’s a “live” object anyway), instead of creating a new one?). Modifying the test to only test hitting a lot of properties in a loop is trivial - just copy&paste a property access many times in the loop.

https://github.com/realm/realm-js/issues/2782#issuecomment-608443330 https://github.com/realm/realm-js/issues/2782#issuecomment-608453197

1reaction
l7xcommented, Apr 3, 2020

Realm is more column oriented and using mmap’ed files. You can find more info about design on their website.

In a way, Realm is more similar to those “deferred” Django properties than typical access patterns, bit with more efficient fetching and less efficient caching.

I do have some ideas about some helper methods which may make converting to POJOs less messy, but I’m in a hurry now, I’ll write them here later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Realm API is Optimized for Performance & Low Memory ...
Learn about the Realm API classes that allow for performant and robust apps.
Read more >
How much overhead, if any, do Realm triggers add to a ...
Do Realm triggers add any overhead to a production cluster, other than the reads and writes they perform on the database?
Read more >
How expensive is it to have a list field with ... - Stack Overflow
Best practice is to keep Realm objects 'Realmy' by leveraging Collections (Results, Lists etc). If your Contacts is a List collection then you ......
Read more >
Realm DB | Android Pitfalls Demystified | by Muhammad Waris
I have been using Realm DB in one of my production apps for over 2 ... is no actual memory consumption and overhead...
Read more >
Performance comparison of Realm and SQLite on iOS
Summary · Realm provides clean interface to stored objects. (SharkORM is also pretty nice compared with dealing with raw SQL though) · Realm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found