by vishnumohandas · 2y ago · 0 comments
[1]: https://github.com/ente-io/edge-db-benchmarks/blob/43273607d...
Edit: Updated the permalink
Edit: You've changed the link after I wrote this reply. Did you fix the code? Is the blog post using the original code or this updated code?
Most people won't be inserting large amounts in a single transaction. Ex webserver with many concurrent clients inserting.
We are executing the entire write in a single batch query.
From what we observed, and have documented, it is the serialization that is causing the bottleneck, not the write itself.
Also, more than writes, it is the latency associated with deserializing the read data into models that pushed us to look at options outside SQLite.
[1]: https://github.com/ente-io/edge-db-benchmarks/blob/43273607d...
But as an end consumer, the overall throughput while using SQLite as the DB engine was not sufficient to serve our use case of reading 100k embeddings.
Looking at the library, it seems it's just using prepared statements outside of a transaction...
https://github.com/powersync-ja/sqlite_async.dart/blob/f994e...
Seems the other commenter is correct that wrapping that line in a tx will fix it.
https://github.com/powersync-ja/sqlite_async.dart/blob/f994e...
I think you may be looking too deeply. It does look like that object will wrap in a tx.
If you use one definition while everyone else is using the other, there’s going to be a loud and confused argument.
Since we are talking about databases, we’d all better be using the former, but I suspect maybe the author is not.
What does this have to do with SQLite?
The original link highlighted this snippet:
Future<void> insertEmbedding(EmbeddingProto embedding) async {
final db = await _database;
await db.writeTransaction((tx) async {
await tx.execute('INSERT INTO $tableName ($columnEmbedding) values(?)',
[embedding.writeToBuffer()]);
});
}
Now highlighted: Future<void> insertMultipleEmbeddings(List<EmbeddingProto> embeddings) async {
final db = await _database;
final inputs = embeddings.map((e) => [e.writeToBuffer()]).toList();
await db.executeBatch(
'INSERT INTO $tableName ($columnEmbedding) values(?)', inputs);
}
Did you post the wrong link the first time and corrected your mistake? Or did you change the snippet because @electroly was right about the code being inefficient?[1]: https://github.com/ente-io/edge-db-benchmarks/blob/43273607d...