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.

Android app freezes with 100K objects dataset

See original GitHub issue

Goal

I’m thinking of building an Android app using Realm.

Over time, its dataset could grow to become huge. So, to make sure I could work with Realm, I have built a simple test project with it.

My goal is to have multiple feeds to filter and group items.

Code (Kotlin)

Here are my test objects:

open class Feed(
        @PrimaryKey
        open var id: Long = 0,

        open var name: String? = "feed$id"
) : RealmObject()

open class Item(
        @PrimaryKey
        open var id: Long = 0,

        open var name: String = "item$id",

        open var feed: Feed? = null
) : RealmObject()

I have a RecyclerView.Adapter that receives a list of items RealmResults<Item> object. Here’s the query:

fun Realm.getItems(feedId: Long): RealmResults<Item> =
        where(Item::class.java)
                .equalTo("feed.id", feedId)
                .findAllSorted("id", Sort.DESCENDING)

Test

My test project dataset:

  • 1 Feed
  • 100K+ Item objects

Issue

Whenever a new Item is created, the UI freezes for 3 to 5 seconds.

If I remove the sorting on the query, the freeze is not so long, but it still breaks. Also, my dataset will be a lot more complex and 100K is just a reference number.

Skipped 159 frames!  The application may be doing too much work on its main thread.
Window 'Window{2850f572 u0 io.test/io.test.activity.MainActivity}' spent 5048.6ms processing the last input event: MotionEvent(…)

Debug

With some method profiling, I noticed that io.realm.internal.TableView.nativeSyncIfNeeded() is the culprit. It is too slow, and it runs in the UI thread.

Question

Is there any optimization I could do to handle a dataset of this size? Thanks.

Version of Realm

Realm version: 1.2.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
nhachichacommented, Sep 29, 2016

Hi @jpsim suggestion, have you tried async queries it call https://github.com/realm/realm-java/blob/master/realm/realm-library/src/main/java/io/realm/RealmResults.java#L909 on completion that will not invoke nativeSyncIfNeeded Cheers

2reactions
Zhuindencommented, Sep 29, 2016

@jpmcosta if there is one thing you could try, it’s RealmRecycleViewAdapter from https://github.com/realm/realm-android-adapters and findAllAsync()?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Studio 3.0 and app freezing - Stack Overflow
I just tried updating my buildToolsVersion to 27.0.1, but it didn't fix the freezing problem for me. I've noticed that it freezes very...
Read more >
App freezes for a couple seconds when loading a big dataset ...
I built a simple app that manages the menu items of a restaurant using Node as a backend, MySQL as the database, Express...
Read more >
Diagnosing Native Crashes | Android Open Source Project
The following sections include common types of native crash, an analysis of a sample crash dump, and a discussion of tombstones.
Read more >
Scaling to 100k Users - Alex Pareto
It's a good a problem to have, but information on how to take a web app from 0 to hundreds of thousands of...
Read more >
Google Maps SDK is crashing -- Solution Offered - Issue Tracker
For me Google Map app appears to be working, just my android app which uses google map sdk crashes. Any ETA on this?...
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