ream.Add(Sequence) in Xamarin?


I’ve built out an application in swift and with realm.add I can save a whole array of realm objects to the realm DB with the updating flag. Is there anything like that in Xamarin? We are experiencing performance issues when trying to save large amounts of objects in Android to the realm DB and it’s also just taking a long time to do. If we could save the whole List of objects to realm at once that would be so much nicer. Any help would be appreciated.


No, that’s not possible with Realm for .NET and even if such an API were exposed, it would not have improved performance. In .NET, there’s a managed to native transition for every property on the object which can’t be avoided regardless of whether you pass in a single object or a collection of objects. Swift/Objective C don’t have that since you’re always working with native code there. What you could do is use the WriteAsync call to perform the transaction on a background thread and avoid blocking the UI. And just for reference, how many objects are you trying to add or update and how long is it taking?


Thank you for the info. I was afraid of that being the answer but wanted to ask just in case. I have a process that runs to “seed” this data. Right now the total data is just over 1 million objects (not heavy object, just names, a date, and ID numbers) and I grab these ~20k at a time and go through them in a loop to add them to Realm. This takes me about 6 or 7 hours. I did the same thing in Swift and had it done in less then 10 min.


This is unreasonably long time for that little data. Can you post your seed code so we can check for some obvious bottlenecks?