realm-java: Bidirectional links Caused slowness when parsing collection changeset

Goal

I think I’ve found a bug that makes Realm freeze while trying to execute transactions to update data.

Results

My schema worked fine in Realm 2.3.0, but it doesn’t seem to work well in Realm 3.1.3.

Steps & Code to Reproduce

I’ve created a simple app to reproduce the bug: https://github.com/jpmcosta/RealmTestProject/tree/47b091215e2517ae337b88f6a5aeb597edf6542d:

  • run the app;
  • click on the FABs and on the items in the list;
    • example: click 5 times on the left FAB, 5 times on right FAB, and then click once or twice on one of the items in the list.
  • the app will eventually freeze and will have to be force closed.
Details of the app:
  • left FAB will create a Filter, replicating my app’s use case (2 transactions):
    • first, updates the data of a temporary Filter;
    • then, copies the temporary Filter data to the actual Filter.
  • right FAB will create an Item for every Feed (1 transaction);
  • clicking on the items in the list (Filters) will update their isEnabled value (1 transaction).

Version of Realm and tooling

Realm version(s): 3.1.3

Android version: 5.1.1 (22)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 18 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I was trying to figure out if there was an infinite loop or not. I’ve modified the test app to run multiple tests on different graphs, but with the same number of objects. Here: https://github.com/jpmcosta/RealmTestProject/tree/cdd686001d5293a1ee3ab7b43ded542ea2b89b0d

The test is simply:

getRealm().executeTransaction(new Realm.Transaction() {

    @Override
    public void execute(Realm realm) {
        Filter filter = realm.where(Filter.class).equalTo("id", 0).findFirst();
        filter.isEnabled = !filter.isEnabled;
    }
});

I’ve tried to remove parentFeed from Item, to see the impact it might have, and I found that if Item has a parentFeed object, the testing times jump from a maximum of ~8000ms to a maximum of ~70000ms.

I’ve run tests 1000+ times, with different OBJECT_COUNT, and indeed it doesn’t seem to exist an infinite loop, just really slow transaction times.

With 10 Apps, 10 Feeds, 10 Items, no repeated links, and 3 Filters pointing to App#0, these were some of my results:

[test 0] time: 2235
[test 1] time: 590
[test 2] time: 144
[test 3] time: 406
[test 4] time: 507
[test 5] time: 373
[test 6] time: 1030
[test 7] time: 270
[test 8] time: 1519
[test 9] time: 1911
[test 1] time: 656
[test 2] time: 16650
[test 3] time: 19002
[test 4] time: 27234
[test 5] time: 13973
[test 6] time: 5564
[test 7] time: 12968
[test 8] time: 69333
[test 9] time: 3139
[test 10] time: 8201

For the specific case here, the Filter actually only has a single direction link to the App. And change Filter.isEnabled should effect other Filter objects in the collection. I think that is something should be optimized in our parsing. But I don’t have too much ideas right now.