Database benchmark: Realm Vs. SnappyDB

Hesam Kamalan
3 min readSep 8, 2016

--

Get rid of SQLite database if storing an object to db and perform a query are only things you need in your application. My problem with default Android database is writing a lot of code for a simple thing.

I considered two databases in my benchmark, Realm (because of lots of good things I heard about it) and SnappyDB (I found Uber is using it). Each provides their benchmark against native SQLite.

Realm Vs. SQLite
SnappyDB Vs. SQLite

As I didn’t find a document compare these two databases, I decided to do it myself by creating and integrating them into an Android project. IT makes me able to compare the speed of Insertion, Finding a list of objects and Deletion of all objects. I tried to use the best method each offer in order to create this benchmark.

Test device

All results are based on Nexus 5 device, Android 6.0.1

Test process

There are few buttons on the screen, as you can see in the screenshot.

Screenshot of the app

Results

I found following results after 10 attempts under different conditions.

Benchmark, Realm Vs. SnappyDB

Findings

  • Realm has a super BIG!!! problem/limitation, Realm doesn’t work in unit tests, Realm works only in instrumentation tests.
  • If you choose a wrong approach you fall in trouble, as I fell. Cost of using transaction is MINUTES!. You see in what extent insertion time dropped from 300s to 1.7s by doing insertion in a transaction (rather than a transaction per insertion as shown here).
  • Read/find time in Realm is pretty fast and almost same if we ignore the first attempt. However, tolerance in SnappyDB is very high from 2ms to 187ms. The worse case happened when I tried to search for `1` and best case happened when I tried to search for `56248`. It shows SnappyDB finds faster when probability of containing a value is low.
  • Realm has a specific way to delete an object type by deleting all types within a transaction. However, I didn’t find such a way for SnappyDB and that’s why it’s much slower, because I’m iterating over a list of objects and delete them one by one.

References

--

--