realm-js: Performance Problems when working with large datasets

Goals

Our app allows users to sort the photos on their device in a unique way. This means they can’t just use the built in photos app to do the sorting.

As a result we have Photos and Albums. We store a URI to the photo and what albums the photo has been sorted to.

Expected Results

Writing 50 records should take less than a second.

Actual Results

If there are more than 5,000 records in the database, adding 50 more takes ~1 second. Since this is react native this absolutely kills the responsiveness of the app.

NOTE: This is definitely a release build, Android.

Steps to Reproduce

I’ll create a repro if necessary, just want to make sure this isn’t expected behaviour before I do.

Code Sample

export class Photo {
	static schema: ObjectSchema = {
		name: 'Photo',
		primaryKey: 'uri',
		properties: {
			timestamp: { type: 'date', indexed: true },
			uri: 'string',
			width: 'double',
			height: 'double',
			albums: 'Album[]',
			inTrash: { type: 'bool', default: false, indexed: true },
			lastSeenImportId: { type: 'string?', indexed: true },
		},
	};

	// ...
}

export class Album {
	static schema: ObjectSchema = {
		name: 'Album',
		primaryKey: 'id',
		properties: {
			id: 'string',
			name: 'string',
			photos: { type: 'linkingObjects', objectType: 'Photo', property: 'albums' },
		},
	};

	// ...
}

Version of Realm and Tooling

  • Realm JS SDK Version: 2.29.2
  • React Native: 0.59.10
  • Client OS & Version: Android, all tested versions.
  • Which debugger for React Native: None, Release build with console.log profiling.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

@kneth so if I’ve understood correctly you’re saying that this is a feature:

  • addListener
  • create
  • In listener, query for objects
  • No objects found

That’s the expected behaviour?

I buy the logic for notifying quickly, and for why there might be a delay in updating existing live objects to reflect the new data, but asking for a new result set needs to return a correct result.

Otherwise how do we actually build a feature with listeners? The app’s UI will be updated quickly but it’ll be wrong. The screen won’t reflect the item the user just added to the DB, and then when it’s “really” there we don’t get any notification to re-render.