(#6031) - faster IDB changes() with batched cursor #6033
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 is a rewrite of #6031. Instead of having two separate implementations of
changes(), I've implemented a newrunBatchedCursor()routine that abstracts away two implementations:getAll()/getAllKeys()-based, for browsers that support itIDBCursor-based, for browsers that don't supportgetAll()/getAllKeys()or for queries where we need cursors (e.g. descending)Mode 1 essentially works by fetching
nchanges for every batch, wherencorresponds tolimitin thechanges()API. In the case ofauto_compacted databases with no conflicts, and when we're not usingopts.filteroropts.doc_ids, this means that we can accomplishchanges()with a single batch (notably this applies to secondary indexes, giving them quite a perf boost).In other cases, we may slightly overfetch, but I'd argue this is still better than fetching one-at-a-time, and that we're still honoring the user's preferences for memory consumption (communicated via
limit). In cases wherelimitis -1/undefined we do not use Mode 1 since it would mean reading the whole DB into memory.Mode 2 works like a classic IDBCursor, as we've done in the past. It's abstracted into Mode 1 by acting like a batched cursor where the batch size is 1.
I ran a benchmark using Firefox 50 and Chrome 55 on a MacBook Air, and got the following results for
temp-viewswith 10 iterations:So roughly, this makes secondary index creation in IDB about 2x faster in Chrome and Firefox. It also has the potential to make replication faster (when pulling from IDB databases) but I need to write a new benchmark to confirm it.