Performance comparison of Android ORM Frameworks

Overview

Performance comparison of Android ORM Frameworks

At the moment there are a lot of ORM-libraries for the Android OS. We reviewed the most popular ones and compared them by performance and some other parameters. As libraries for comparison, the most popular solutions at the time of writing were chosen: ORMLite, Sugar ORM, Freezer, DBFlow, requery, GreenDAO, ActiveAndroid, Room, Sprinkles. Also in the comparison participated "clean" SQLite - the built-in API for working with SQLite in Android, without the use of ORM, and the popular NoSql solution - Realm.

We considered 3 variants(simple, complex, balanced), and for each of them 4 operations(CRUD).

Models

public class Library{ 
    String address;
    String name;
}

public class Book{
    String author;
    String title;
    int pagesCount;
    int bookId; 
    Library library;
}
public class Person{
    String firstName;
    String secondName;
    Date birthdayDate;
    String gender;
    long phone;
    Library library;
}

Test cases

  • Simple - 1 Library object per 1000 Book objects
  • Complex - 1 Library object for 500 Book objects and 400 Person objects (5 Libraries, 2500 Books, 2000 Persons)
  • Balanced - 1 Library object for 50 Book objects and 50 Person objects (50 Libraries, 2500 Books, 2500 Persons)

For each test cache/lazy initialization were turned off, and we perform an average of 10 measurements per operation.

Results Table

Library write(s) read(s) update(s) delete(s) write(c) read(c) update(c) delete(c) write(b) read(b) update(b) delete(b)
ORMLite 151 666 122 105 445 3836 857 811 1563 3426 724 728
SugarORM 245 842 252 152 1402 4129 1467 1003 2204 4397 1702 1197
Freezer 248 5430 240 4797 1337 78982 2221 22104 3255 134942 1887 29515
DBFlow 97 757 459 186 360 3534 3124 1044 1129 4653 5204 1268
Requery 87 1501 147 129 461 8057 861 802 1368 8002 886 763
Realm 151 29 1079 723 698 688 19666 9180 1522 210 21129 10006
GreenDAO 81 1238 117 97 357 5552 455 274 598 5905 504 315
ActiveAndroid 3123 930 2293 2423 14671 4165 15958 13023 17213 4653 19303 14642
Sprinkles 5766 1050 6364 605 25978 4334 65579 2428 27774 4526 37705 2519
Room 131 699 170 109 562 3201 717 403 1330 3532 790 507
SQLite 50 436 63 80 386 2155 192 284 1146 2313 213 318

Histograms

Overal

More detailed (Simple)

More detailed (Complex)

More detailed (Balanced)

Summary

ORMLite

It does not save much from the boilerplate code, however one of the fastest libraries out there is built-in caching and delayed initialization, good documentation. Despite all the advantages, I would not use it, because The main reason for using ORM is getting rid of writing repetitive code, and, therefore, speeding up development, which in other libraries is realized, in my opinion, better.

SugarORM

Of the advantages can be noted ease of use, which is not enough in ORMLite, and that's it. Has a separate drawback associated with the approach to implementation - it is not "friendly" with Instant Run, so when working with it you have to disable it.

Freezer

A relatively young library is not widely distributed. Comfortable, but do not make any complicated manipulations with it. In addition, the speed of work, to put it mildly, leaves much to be desired.

DBFlow

One of the best in the parameters outlined in this article. One of the fastest write / read operations is the average update / delete speed. According to the parameters presented in Table 2, it is the best on a par with Realm. In my opinion, is one of the best alternatives.

Requery

Quite a controversial decision, in the fall because of problems with installation and documentation (if used without RXJava). If you understand, working with it becomes convenient. Supports different databases, rich functionality.

Realm

A relatively fast and convenient library, all links are simply implemented, which is related to the object orientation of the database, even reading "clean" SQLite even when manually cached for it by reading. Excellent documentation. Is, perhaps, one of the best option for storing data on a mobile device at the moment, the minus can only be an increase in the size of the apk-file by 2.5 MB. For all ORMs, except for Realm, built-in object caching was disabled, hence the readings.

GreenDao

It is flexible and convenient to use one-to-many communication, but very unpleasant code generation, as a result of which your classes will be filled with a bunch of methods and comments. In addition, you need to connect the Gradle plug-in, which greatly increases the build time. Also, developers presented their database - ObjectBox - object database, which they position as the fastest, comparable to GreenDao, ORM.

ActiveAndroid

Not very fast, but quite convenient and proven over time solution. Quite popular, but because you can find many articles, solutions to issues and other things, which reduces the appearance of "unresolvable" problems to a minimum.

Sprinkles

Each entry is accompanied by an unnecessary sample (SELECT * FROM% s WHERE% s LIMIT 1). From sql-requests too does not rescue. Performance indicators are the worst of the submitted. Therefore, there is no reason to use it for your projects.

Room

An interesting solution presented on Google I / O 2017 as optimal for working with the database on Android OS. Despite the fact that it is necessary to use explicit sql-requests, the library turned out to be quite convenient and I liked it personally. On performance is in the lead, so I would advise you to choose this particular library. Since this solution, submitted by Google, it will quickly become popular, and, therefore, there will be no problems with finding solutions to problems that occur along with it.

SQLite

A lot of code, longer in time, but speed and flexibility are still unmatched.

Сonclusion

Summing up, the most "fast" ORMs were Realm, GreenDAO, ORMLite and Room, but if performance is critical for the project, a "clean" SQLite with a custom cache is still the best choice. On the other parameters, the best are Realm, DBFlow and GreenDAO. Thus, for small projects and projects of medium complexity, I recommend using DBFlow or GreenDAO, if the size of apk is not important - Realm. Realm and Room are suitable for large projects. And only if their capabilities for some reason are not enough, or the ORM-approach is not for you, to return to using the built-in API for SQLite.

In addition to those discussed in the article, initially ORMs such as AndrORM, OHibernate, MemoryORM, ORMDroid, StromIO were also involved in the review, which were dropped for one reason or another.

All measurements were made on the Samsung S7 device.

You might also like...
a 3d database ORM experiment. (used in two commercial projects)

Android-TriOrm a 3d database ORM experiment for Android. (used in two commercial projects). based around small tables concept and JVM Serialization. H

JAKO: Just Another Kotlin Orm (PostgreSQL)
JAKO: Just Another Kotlin Orm (PostgreSQL)

JAKO: Just Another Kotlin Orm (PostgreSQL) JAKO is a simple, minimal, no-dependency library to build and execute postgresql statements using a fluent

Active record style SQLite persistence for Android

ActiveAndroid ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to s

Object-relational mapping for Android

RushOrm Object-relational mapping for Android RushOrm replaces the need for SQL by mapping java classes to SQL tables. What is the aim? The aim is to

Insanely easy way to work with Android Database.

Sugar ORM Insanely easy way to work with Android databases. Official documentation can be found here - Check some examples below. The example applicat

requery - modern SQL based query & persistence for Java / Kotlin / Android
requery - modern SQL based query & persistence for Java / Kotlin / Android

A light but powerful object mapping and SQL generator for Java/Kotlin/Android with RxJava and Java 8 support. Easily map to or create databases, perfo

Core Data for Android

NexusData Core Data for Android NexusData is an object graph and persistence framework for Android. It allows for organizing and managing relational d

A simple NoSQL client for Android. Meant as a document store using key/value pairs and some rudimentary querying. Useful for avoiding the hassle of SQL code.

SimpleNoSQL A simple NoSQL client for Android. If you ever wanted to just save some data but didn't really want to worry about where it was going to b

An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

Comments
  • Room results are incorrect case of using foreach instead of Room relationships

    Room results are incorrect case of using foreach instead of Room relationships

    In Room there are approaches that could be used to define the relations between the entities:

    1. @Embedded (nested objects)
    2. @ForeignKey
    3. @Relation In test should have been using relationship instead of two sequential request and foreach to bind a library to a book. My simple read results with foreach are about 400ms comparing to using @Embedded relationship they are 30ms.
    opened by axrkozlov 0
  • Realm results are incorrect because they assume cache

    Realm results are incorrect because they assume cache

    It is not possible to use Realm with cache and still be threadsafe. Therefore it is misleading to put Realms very fast cache read time, when in practice you are going to have to do all multi-threading yourself. The issue comes down to Realm not being able to see changes on other threads. In order to see a transaction committed on another thread you have to close and open the realm connection on that thread (aka read from disk).

    opened by Josh-Allen-ConnectedLab 0
  • Clarifications

    Clarifications

    First of all good job, i really appreciated your comparsion it helped me a lot but i woud like to suggest a few fixes on the presentation of the results

    After you describe the test cases and put the result table, you should inform which unity represents the informed value and WHAT IS THE DESIRED VALUE (lower better)

    Your two first columns are read and write... at first sight i thought those numbers represented the number of operations something like IO/time, in which case high numbers are better.

    It took me few minutes, scroll up and down until i notice the histograms and realize that those numbers meant the total time to realize the batch of operations

    opened by bolds07 0
  • The histogram and the result table don't match

    The histogram and the result table don't match

    The write and read columns are probably the other way around in results table. The results table shows the realm is best for read operations while the histograms show that its the case for write operations.

    opened by DeepakSenapati 1
Owner
Alexey Zatsepin
Alexey Zatsepin
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.

Check out ObjectBox Check out our new mobile database ObjectBox (GitHub repo). ObjectBox is a superfast object-oriented database with strong relation

Markus Junginger 12.6k Jan 3, 2023
Android ORM

Shillelagh Shillelagh is an sqlite library. It was built to make life easier. The entire library was built around simplicity when using sqlite in Andr

Andrew Reitz 49 Sep 11, 2020
Compile-time active record ORM for Android

Ollie Compile-time active record ORM for Android. Multiple mapping methods. SQLiteDatabase-like interface (QueryUtils.java). Lightweight query builder

Michael Pardo 423 Dec 30, 2022
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Andrew Grosner 4.9k Dec 30, 2022
lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)

Description ORMAN is an minimalistic and lightweight ORM framework for Java which can handle your common database usage without writing SQL and strugg

Ahmet Alp Balkan 246 Nov 20, 2022
ORMDroid is a simple ORM persistence framework for your Android applications.

ORMDroid is a simple ORM persistence framework for your Android applications, providing an easy to use, almost-zero-config way to handle model persist

Ross Bamford 87 Nov 10, 2022
AndroidQuery is an Android ORM for SQLite and ContentProvider which focuses on easy of use and performances thanks to annotation processing and code generation

WARNING: now that Room is out, I no longer maintain that library. If you need a library to easy access to default android ContentProvider, I would may

Frédéric Julian 19 Dec 11, 2021
LiteOrm is a fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line of code efficiently.

#LiteOrm:Android高性能数据库框架 A fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line

马天宇 1.5k Nov 19, 2022
lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)

Description ORMAN is an minimalistic and lightweight ORM framework for Java which can handle your common database usage without writing SQL and strugg

Ahmet Alp Balkan 246 Nov 20, 2022
An ORM for Android with type-safety and painless smart migrations

Android Orma Orma is a ORM (Object-Relation Mapper) for Android SQLiteDatabase. Because it generates helper classes at compile time with annotation pr

The Maskarade project 440 Nov 25, 2022