Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions firebase-firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
[#7376](//github.com/firebase/firebase-android-sdk/issues/7376)
- [changed] Improve query performance via internal memoization of calculated document data.
[#7370](//github.com/firebase/firebase-android-sdk/issues/7370)
- [changed] Improve query performance by avoiding excessive Comparator instance creation.
[#7388](//github.com/firebase/firebase-android-sdk/pull/7388)

# 26.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.firebase.firestore.remote.TargetChange;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -156,6 +157,7 @@ public DocumentChanges computeDocChanges(
? oldDocumentSet.getFirstDocument()
: null;

Comparator<Document> queryComparator = query.comparator();
for (Map.Entry<DocumentKey, Document> entry : docChanges) {
DocumentKey key = entry.getKey();
Document oldDoc = oldDocumentSet.getDocument(key);
Expand All @@ -182,9 +184,9 @@ public DocumentChanges computeDocChanges(
changeSet.addChange(DocumentViewChange.create(Type.MODIFIED, newDoc));
changeApplied = true;

if ((lastDocInLimit != null && query.comparator().compare(newDoc, lastDocInLimit) > 0)
if ((lastDocInLimit != null && queryComparator.compare(newDoc, lastDocInLimit) > 0)
|| (firstDocInLimit != null
&& query.comparator().compare(newDoc, firstDocInLimit) < 0)) {
&& queryComparator.compare(newDoc, firstDocInLimit) < 0)) {
// This doc moved from inside the limit to outside the limit. That means there may be
// some doc in the local cache that should be included instead.
needsRefill = true;
Expand Down Expand Up @@ -296,15 +298,17 @@ public ViewChange applyChanges(
mutatedKeys = docChanges.mutatedKeys;

// Sort changes based on type and query comparator.

List<DocumentViewChange> viewChanges = docChanges.changeSet.getChanges();
Comparator<Document> queryComparator = query.comparator();
Collections.sort(
viewChanges,
(DocumentViewChange o1, DocumentViewChange o2) -> {
int typeComp = Integer.compare(View.changeTypeOrder(o1), View.changeTypeOrder(o2));
if (typeComp != 0) {
return typeComp;
}
return query.comparator().compare(o1.getDocument(), o2.getDocument());
return queryComparator.compare(o1.getDocument(), o2.getDocument());
});
applyTargetChange(targetChange);
List<LimboDocumentChange> limboDocumentChanges =
Expand Down
Loading