Interested in speaking at MongoDB World 2022? Click here to become a speaker.
HomeLearnArticleRealm Core Database 6.0: A New Architecture and Frozen Objects

Realm Core Database 6.0: A New Architecture and Frozen Objects

Updated: Oct 19, 2020 |

Published: May 29, 2020

  • MongoDB
  • Mobile
  • Realm
  • ...

By Shane McAllister

, Katherine Maughan

, and Ian Ward

Rate this article

#TL;DR

Realm is an easy-to-use, offline-first database that lets mobile developers build better apps faster.

Since the acquisition by MongoDB of Realm in May 2019, MongoDB has continued investing in building an updated version of our mobile database; culimating in the Realm Core Database 6.0.

We're thrilled to announce that it's now out of beta and released; we look forward to seeing what apps you build with Realm in production. The Realm Core Database 6.0 is now included in the 10.0 versions of each SDK: Kotlin/Java, Swift/Obj-C, Javascript on the node.js & React Native, as well as .NET support for a variety of UWP platforms and Xamarin. Take a look at the docs here.

#A New Architecture

This effort lays a new foundation that further increases the stability of the Realm Database and allows us to quickly release new features in the future.

We've also increased performance with further optimizations still to come. We're most excited that:

  • The new architecture makes it faster to look up objects based on a primary key
  • iOS benchmarks show faster insertions, twice as fast sorting, and ten times faster deletions
  • Code simplifications yielded a ten percent reduction in total lines of code and a smaller library
  • Realm files are now much smaller when storing big blobs or large transactions

#Frozen Objects

With this release, we're also thrilled to announce that Realm now supports Frozen Objects, making it easier to use Realm with reactive frameworks.

Since our initial release of the Realm database, our concept of live, thread-confined objects, has been key to reducing the code that mobile developers need to write. Objects are the data, so when the local database is updated for a particular thread, all objects are automatically updated too. This design ensures you have a consistent view of your data and makes it extremely easy to hook the local database up to the UI. But it historically came at a cost for developers using reactive frameworks.

Now, Frozen Objects allows you to work with immutable data without needing to extract it from the database. Frozen Objects act like immutable objects, meaning they won't change. They allow you to freeze elements of your data and hand it over to other threads and operations without throwing an exception - so it's simple to use Realm when working with platforms like RxJava & LiveData, RxSwift & Combine, and React.

#Using Frozen Objects

Freeze any 'Realm', 'RealmList', or 'RealmObject' and it will not be possible to modify them in any way. These Frozen Objects have none of the threading restrictions that live objects have; meaning they can be read and queried across all threads.

As an example, consider what it would look like if you were listening to changes on a live Realm using Kotlin or .NET, and then wanted to freeze query results before sending them on for further processing. If you're an iOS developer please check out our blog post on RealmSwift integration with Combine

The Realm team is proud to say that we've heard you, and we hope that you give this feature a try to simplify your code and improve your development experience.

1var realm = Realm.GetInstance();
2var frozenResults = realm.All<Person>()
3 .Where(p => p.Name.StartsWith("Jane"))
4 .Freeze();
5
6Assert.IsTrue(results.IsFrozen());
7Task.Run(() =>
8{
9 // it is now possible to read objects on another thread
10 var person = frozenResults.First();
11 Console.WriteLine($"Person from a background thread: {person.Name}");
12});

Since Java needs immutable objects, we also updated our Java support so all Realm Observables and Flowables now emit frozen objects by default. This means that it should be possible to use all operators available in RxJava without either using Realm.copyFromRealm() or running into an IllegalStateException:

1val realm = Realm.getDefaultInstance()
2val stream: Disposable = realm.where<Person>().beginsWith("name", "Jane").findAllAsync().asFlowable()
3 .flatMap { frozenPersons ->
4 Flowable.fromIterable(frozenPersons)
5 .filter { person -> person.age > 18 }
6 .map { person -> PersonViewModel(person.name, person.age) }
7 .toList()
8 .toFlowable()
9 }
10 .subscribeOn(Schedulers.computation())
11 .observeOn(AndroidSchedulers.mainThread)
12 .subscribe { updateUI(it) }
13 }

If you have feedback please post it in Github and the Realm team will check it out!

#A Strong Foundation for the Future

The Realm Core Database 6.0 now released with Frozen Objects and we're now focused on adding new features; such as new types, new SDKs, andunlocking new use cases for our developers.

Want to Ask a Question? Visit our Forums

Want to make a feature request? Visit our Feedback Portal

Want to be notified of upcoming Realm events such as our iOS Hackathon in November2020? Visit our Global Community Page

Safe Harbor

The development, release, and timing of any features or functionality described for our products remains at our sole discretion. This information is merely intended to outline our general product direction and it should not be relied on in making a purchasing decision nor is this a commitment, promise or legal obligation to deliver any material, code, or functionality.

Rate this article
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.