-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[For review only] Minimize rereading of batches in [FSTLocalDocumentsView documentsMatchingCollectionQuery] #1527
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm convinced that at the close of this loop, you can assert that matchingKeys will be empty. Try it!
If so, I believe this whole thing can be simplified as to:
Applying should be like this (sorry for pseudocode):
Note query filtering doesn't happen on the intermediate states, only on the final.
At that point I think you can delete
localDocuments
anddocumentsForKeys
.localDocument
will have just a single caller and can be inlined intodocumentForKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, four integration tests trigger the case when
matchingKeys
are not empty. They all involve writing new documents to a collection while being offline, e.g. testGetCollectionWhileOfflineWithDefaultSource. If I understand the code correctly,remoteCache
only contains the documents which were ack'ed by the server, andlocalDocuments
only applies local changes to given documents, which would leave the offline-createddoc4
out ofresults
if checkingbatches
was omitted.I'd be happy to get rid of
localDocument
somehow, though. Let me know if you can think of a way around the offline issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should be happening is that while those documents aren't in the remote documents cache, they are in the mutation queue, so when you iterate through the batches and apply them to results the new documents should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard previous comments, let me try it out...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strategy that localDocuments applies today does not work for what I'm proposing.
It says essentially, for each key already present, apply all mutations for exactly that key to produce the final view of the document.
My proposal in the pseudocode above is to process all mutations that apply to the query such that the mutation will create new documents that don't have a value in remote documents yet.
Note that batches can contain mutations that are in different collections. These batches match the query even though not all the mutations in the batch do. Mutations can't change the key a document though. This is why it's safe to disregard these mutations before the local view has been fully assembled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this look right?
(apart from refactoring potential, it actually gives a speed improvement as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This function's execution time is now dominated by
dictionaryBySettingObject
(called directly and by remote document cache). Perhaps migrating to C++ version of immutable map might improve timings further.