Hi I am developing a Xamarin app that load lots of lines ( around 10K )
I got really poor performance something like 2 minutes to insert 5K lines of an object.
I use InsertOrReplaceWithChildren:
public bool Insert_Update_Many<T>(List<T> obj)
{
try
{
lock (this.Lock) {
_connection.RunInTransaction(() => {
_connection.InsertOrReplaceAllWithChildren(obj, true);
});
}
return true;
}
catch (Exception ex)
{
Debug.WriteLine("[SQLITE_ERROR]: " + ex.ToString());
return false;
}
}
Since I add "RunInTransaction" I got an improvement (before it was 5 min+).
My objects contains relations ships.
Is there any way to optimize that ?
It's hard to tell without seeing the actual code, but I faced few issues that may affect performance:
InsertOrReplace
performance is bad : Try calling simple Insert
statements instead of InsertOrReplace
. In some scenarios this may have a big impact. update
operations after insert : this is simple to workaround, you can assign foreign keys by yourself and call plain SQLite.Net Insert
on database intensive operations. 您可以使用WAL模式提高插入性能:
var journalMode = await globalConn.ExecuteScalarAsync<string>("PRAGMA journal_mode = wal");
Here's a suggestion:
Try with raw queries, or actually, first profile the code, maybe there's a bottleneck somewhere in there.
And if you get nothing, I guess you'll just have to do it async and have user wait ( or ship the database file with your app )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.