sync_local: Re-use prepared statements #79
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This keeps prepared statements around for the last table, to avoid preparing a new statement for every row that we insert/delete.
I did not fully confirm, but I expect that the way the query plan is structured that the rows would typically be processed one table at a time, making it efficient to only keep the tables for the last query. It is not an issue if the order is different - we may just lose a little of the performance benefits here.
In my tests on native desktop with an in-memory db, this reduced the overall sync_local duration by around 25% (2786ms -> 2075ms for 500k rows). When taking into account filesystem overhead, the impact will be a little less, but still significant.