Skip to content
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

Use lazy encoding in utf-8 encoded string comparison #6706

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

milaGGL
Copy link
Contributor

@milaGGL milaGGL commented Feb 18, 2025

The previous fix created a performance issue due to expensive UTF-8 encoding. Update compareUtf8Strings to use lazy encoding instead.

Copy link
Contributor

github-actions bot commented Feb 18, 2025

Release note changes

The following release notes were modified. Please ensure they look correct.

Release Notes
firebase-firestore
### {{firestore}} version 25.1.3 {: #firestore_v25-1-3}

* {{fixed}} Use lazy encoding in UTF-8 encoded byte comparison for strings to solve performance issues. GitHub [#6706](//github.com/firebase/firebase-android-sdk/issues/6706){: .external}

#### {{firestore}} Kotlin extensions version 25.1.3 {: #firestore-ktx_v25-1-3}

The Kotlin extensions library transitively includes the updated
`firebase-firestore` library. The Kotlin extensions library has no additional
updates.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 18, 2025

Coverage Report 1

Affected Products

  • firebase-firestore

    Overall coverage changed from 45.74% (95bbf92) to 45.75% (f3d0a04) by +0.01%.

    FilenameBase (95bbf92)Merge (f3d0a04)Diff
    DeleteMutation.java90.48%95.24%+4.76%
    LruGarbageCollector.java97.27%93.64%-3.64%
    Util.java73.94%75.48%+1.54%

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/hXmY7UXnNf.html

Copy link
Contributor

github-actions bot commented Feb 18, 2025

Test Results

  186 files  +  166    186 suites  +166   4m 44s ⏱️ + 4m 32s
1 235 tests +1 119  1 219 ✅ +1 103  16 💤 +16  0 ❌ ±0 
2 494 runs  +2 262  2 462 ✅ +2 230  32 💤 +32  0 ❌ ±0 

Results for commit 8159f25. ± Comparison against base commit 95bbf92.

This pull request removes 116 and adds 1235 tests. Note that renamed tests count towards both.
com.google.firebase.vertexai.GenerativeModelTesting ‑ exception thrown when using invalid location
com.google.firebase.vertexai.GenerativeModelTesting ‑ system calling in request
com.google.firebase.vertexai.SchemaTests ‑ basic schema declaration
com.google.firebase.vertexai.SchemaTests ‑ full schema declaration
com.google.firebase.vertexai.StreamingSnapshotTests ‑ citation parsed correctly
com.google.firebase.vertexai.StreamingSnapshotTests ‑ empty content
com.google.firebase.vertexai.StreamingSnapshotTests ‑ http errors
com.google.firebase.vertexai.StreamingSnapshotTests ‑ image rejected
com.google.firebase.vertexai.StreamingSnapshotTests ‑ invalid api key
com.google.firebase.vertexai.StreamingSnapshotTests ‑ invalid json
…
com.google.firebase.firestore.AggregateQuerySnapshotTest ‑ createWithCountShouldReturnInstanceWithTheGivenQueryAndCount
com.google.firebase.firestore.AggregateQueryTest ‑ testSourceMustNotBeNull
com.google.firebase.firestore.BlobTest ‑ testComparison
com.google.firebase.firestore.BlobTest ‑ testEquals
com.google.firebase.firestore.BlobTest ‑ testMutableBytes
com.google.firebase.firestore.CollectionReferenceTest ‑ testEquals
com.google.firebase.firestore.DocumentChangeTest ‑ randomTests
com.google.firebase.firestore.DocumentChangeTest ‑ testAdditions
com.google.firebase.firestore.DocumentChangeTest ‑ testChangesWithSortOrderChange
com.google.firebase.firestore.DocumentChangeTest ‑ testDeletions
…

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 18, 2025

Size Report 1

Affected Products

  • firebase-firestore

    TypeBase (95bbf92)Merge (f3d0a04)Diff
    aar1.45 MB1.45 MB+312 B (+0.0%)
    apk (release)11.4 MB11.4 MB+256 B (+0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/vvBXRPkHnO.html

@milaGGL milaGGL marked this pull request as ready for review February 19, 2025 15:14
@milaGGL milaGGL requested a review from ehsannas February 19, 2025 15:15
return Integer.compare(leftCodePoint, rightCodePoint);
} else {
// substring and do UTF-8 encoded byte comparison
byte[] leftBytes = getUtf8SafeBytes(left, i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be wrong to always take (index, index+2), and compare those?

meaning, getting rid of getUtf8SafeBytes()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the unit test results, yes, somehow it is problematic for java, while js managed to handle it nicely. But, increasing i one by one + getUtf8SafeBytes() solved the problem.

@milaGGL milaGGL requested a review from ehsannas February 20, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants