Accelerate SQLite bulk inserts - #170
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR speeds up SQLite-backed bulk inserts without changing the MongoDB-compatible behavior exposed by TinyMongo.
CodeandBinary._idacross candidate checks, retries, and commits.Why
Profiling showed that most bulk-insert time was spent above SQLite: repeated BSON checks, JSON serialization, identity-key construction, and candidate planning. The new prepared-row path removes that duplicate work. For a brand-new compatible table, the optimistic path also skips the general conflict planner after proving under a write transaction that the table is empty and safe.
Contract and safety boundaries
The optimistic path is deliberately narrow:
Local benchmark
Median local throughput for 10,000-document batches:
masterw=1, j=true)The initial-load path is about 5.35x faster than the previous TinyMongo SQLite baseline and about 19% faster than the prepared-only stage. MongoDB results were noisier across runs; its comparison explicitly used acknowledged, journaled writes. Direct SQLite is an implementation ceiling rather than a contract-equivalent comparison.
Validation
3744 passed, 1 skipped, 531 deselected100%across 8,314 statements and 3,524 branchesruff check .black --check .git diff --check