realm-java: Commiting transaction slow
Hi there,
I’m using Android Realm 3.3.1. I load a csv with 800k lines into Realm.
To do so I parse the csv, map each line into a Java bean (with a Pools.SynchronizedPool
) and inserting every 1000 records into a transaction block.
Here is the block (timeCounter.getStep()
is giving me elapsed time since the TimeCounter.get()
)
final TimeCounter timeCounter = TimeCounter.get();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.insert(items);
long delayToInsert = timeCounter.getStep();
log.debug("Saved %d items in %d ms", items.size(), delayToInsert);
}
});
log.debug("Commit transaction in %d ms", timeCounter.getStep());
Here is the result after a while (around 100k inserted) :
Saved 1000 items in 351 ms
Commit transaction in 1180 ms
The insert always takes 300~500ms but the transaction commit is getting bigger and bigger with time. It starts around 500ms (just a bit more than the simple insert), but ends more than 3000ms.
You can see that the monitoring is fine
So I’m a doing something wrong ?
Edit : I tried async transaction, it’s worse
Edit2 : Removing @PrimaryKey
from the Java Bean helps a lot, but still, transactions commit time is going up slowly (800ms after 250k inserted)
Edit3 : No @PrimaryKey
, inserting 880k with batch of 5000, starting at 1900ms, finishing at 3000ms. It’s better but not perfect. Still looking for a solution, our csv will grow up
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 32 (29 by maintainers)
@mgohin If you only have the Realm opened on the UI thread and in one AsyncTask, then that shouldn’t be the issue you are seeing as the UI Realm is automatically kept up to date.