Conversation
Collaborator
Size Report 1Affected Products
Test Logs
|
Collaborator
Startup Time Report 1Note: Layout is sometimes suboptimal due to limited formatting support on GitHub. Please check this report on GCS. Notes
Startup Times
|
Contributor
Author
|
/gemini review |
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the previous UTF-8 byte-oriented string comparison with a more efficient surrogate-aware char-by-char algorithm and updates the changelog to document the fix.
- Simplified
compareUtf8Stringsto a single-pass char comparison usingCharacter.isSurrogate - Removed
ByteStringfallback and eliminated codePoint/substring overhead - Added an unreleased entry in
CHANGELOG.mdfor the performance fix
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| firebase-firestore/src/main/java/com/google/firebase/firestore/util/Util.java | Rewrote compareUtf8Strings with optimized surrogate-aware logic; removed helper and ByteString paths |
| firebase-firestore/CHANGELOG.md | Documented the UTF-8 comparison performance improvement under Unreleased |
Comments suppressed due to low confidence (2)
firebase-firestore/src/main/java/com/google/firebase/firestore/util/Util.java:90
- Update this Javadoc to describe the new surrogate-aware, char-by-char comparison algorithm rather than the previous byte-level UTF-8 logic.
/** Compare strings in UTF-8 encoded byte order */
firebase-firestore/src/main/java/com/google/firebase/firestore/util/Util.java:113
- Add unit tests covering edge cases around surrogate pairs versus non-surrogate characters to verify the new comparison logic across diverse Unicode inputs.
for (int i = 0; i < length; i++) {
firebase-firestore/src/main/java/com/google/firebase/firestore/util/Util.java
Outdated
Show resolved
Hide resolved
firebase-firestore/src/main/java/com/google/firebase/firestore/util/Util.java
Show resolved
Hide resolved
wu-hui
approved these changes
Jul 4, 2025
Contributor
wu-hui
left a comment
There was a problem hiding this comment.
This is wonderful, thanks Denver!
firebase-firestore/src/main/java/com/google/firebase/firestore/util/Util.java
Show resolved
Hide resolved
dconeybe
added a commit
to googleapis/java-firestore
that referenced
this pull request
Jul 7, 2025
The semantics of this logic were originally fixed by #1967, but this fix caused a material performance degradation, which was then improved by #2021. The performance was, however, still suboptimal, and this PR further improves the speed back to close to its original speed and, serendipitously, simplifies the algorithm too. This commit effectively ports the following two PRs from the firebase-android-sdk repository: - firebase/firebase-android-sdk#7098 - firebase/firebase-android-sdk#7109
This was referenced Jul 7, 2025
fix: Further improve performance of the UTF-8 string comparison logic
googleapis/java-firestore#2182
Merged
Open
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Further improved performance of UTF-8 string ordering logic, which had degraded in v25.1.2 due to the fix #6615 and received some improvements in v25.1.3 by the fix #6706. Even with these improvements, customers still observed a material performance degradation (#7053), which this PR addresses.
This PR was ported to the other Firestore SDKs:
Porting to firebase-ios-sdk is not required because it uses UTF-8 encoding natively. In contrast, Java and JavaScript use UTF-16 natively and require special comparison logic to order strings by their UTF-8 encoding lexicographically.
Fixes: #7053