React Native performance issues on write

Whenever I execute a write transaction in my React Native app, the app freezes. Sometimes it freezes for a fraction of a second, sometimes it’s much much longer. This is happening in production (release mode on a new iOS device). I’m trying to figure out a way to get the realm logic off of the main thread, but it looks like React Native just isn’t great at doing that (maybe I’m overlooking something very obvious though).

My ideas so far have been:

  • Figure out a way to spin up a Web Worker or something to handle db logic (RN definitely doesn’t make this easy)
  • Move everything Realm related into a native module (this seems the most doable)
  • Move Realm logic server-side, but this seems to go against being offline-first, so this is definitely not preferable

It would be great to get some guidance on what strategies have been successful in the past and what the best practices are for improving Realm performance on React Native or at least refactoring so as to not affect the user directly.

Another solution I recently stumbled across is the nodejs-mobile-react-native npm package that provides a React Native bridge for this project: I’m not sure how it compares to some of the other “multithreading”/web worker libraries out there (that really don’t look great), so it might be something to consider.