Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQLite write locking #310

Merged
merged 2 commits into from
Jan 28, 2022
Merged

Fix SQLite write locking #310

merged 2 commits into from
Jan 28, 2022

Conversation

mplorentz
Copy link
Member

#305 This removes the db.transaction wrapper in ViewDatabase.fillMessages(). While wrapping our writes to SQLite in a transaction gives a small (~6%) speed boost to the write operations, it creates an exclusive lock on the database, preventing any other reads or writes from taking place. By inserting rows individually instead of in a transaction, we allow readers to read from the database in between insertions. This is important when we are copying over large amounts of data from go-ssb, as a big write transaction can take more than 10 seconds. And it fits with our general strategy of using SQLite as a cache layer and optimizing it for read performance.

@@ -2340,157 +2340,155 @@ class ViewDatabase {

var reports = [Report]()
var skipped: UInt = 0
try db.transaction { // also batches writes! helps a lot with perf
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the only important change to this file. This line (and it's closing brace) were removed. Everything else was an indentation change, but Github doesn't show it that way.

@mplorentz mplorentz merged commit ff35e43 into master Jan 28, 2022
@mplorentz mplorentz deleted the fix-sqlite-write-locking branch January 28, 2022 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant