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

Add double to bit encoding for OrderedCode #5816

Merged
merged 5 commits into from Jan 4, 2022

Conversation

schmidt-sebastian
Copy link
Contributor

This ports the double encoding from https://github.com/firebase/firebase-android-sdk/blob/master/firebase-firestore/src/main/java/com/google/firebase/firestore/index/OrderedCodeWriter.java

Note that Android does not have tests for this code since it is just a copy of the backend code.

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2021

⚠️ No Changeset found

Latest commit: 51d2784

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 15, 2021

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (3d8109c)Merge (35722b9)Diff
    esm5284 kB284 kB+3 B (+0.0%)
    main426 kB426 kB-6 B (-0.0%)
    react-native228 kB228 kB+1 B (+0.0%)
  • @firebase/firestore-lite

    TypeBase (3d8109c)Merge (35722b9)Diff
    browser72.5 kB72.5 kB+10 B (+0.0%)
    esm585.7 kB85.7 kB+3 B (+0.0%)
    main125 kB125 kB-8 B (-0.0%)
    module72.5 kB72.5 kB+10 B (+0.0%)
  • bundle

    12 size changes

    TypeBase (3d8109c)Merge (35722b9)Diff
    firestore (Persistence)229 kB229 kB-28 B (-0.0%)
    firestore (Query Cursors)189 kB189 kB-28 B (-0.0%)
    firestore (Query)190 kB190 kB-28 B (-0.0%)
    firestore (Read data once)178 kB178 kB-28 B (-0.0%)
    firestore (Realtime updates)180 kB180 kB-28 B (-0.0%)
    firestore (Transaction)163 kB163 kB-28 B (-0.0%)
    firestore (Write data)162 kB162 kB-28 B (-0.0%)
    firestore-lite (Query Cursors)56.3 kB56.3 kB-28 B (-0.0%)
    firestore-lite (Query)59.4 kB59.4 kB-28 B (-0.0%)
    firestore-lite (Read data once)43.9 kB43.8 kB-28 B (-0.1%)
    firestore-lite (Transaction)61.2 kB61.2 kB-28 B (-0.0%)
    firestore-lite (Write data)46.8 kB46.8 kB-28 B (-0.1%)

  • firebase

    14 size changes

    TypeBase (3d8109c)Merge (35722b9)Diff
    firebase-analytics.js107 kB107 kB+151 B (+0.1%)
    firebase-app-check.js89.8 kB89.9 kB+151 B (+0.2%)
    firebase-app.js51.3 kB51.4 kB+151 B (+0.3%)
    firebase-auth.js411 kB411 kB+151 B (+0.0%)
    firebase-compat.js753 kB753 kB-27 B (-0.0%)
    firebase-firestore-compat.js280 kB280 kB+520 B (+0.2%)
    firebase-firestore-lite.js245 kB249 kB+3.59 kB (+1.5%)
    firebase-firestore.js766 kB770 kB+3.56 kB (+0.5%)
    firebase-functions.js30.9 kB31.1 kB+151 B (+0.5%)
    firebase-messaging-sw.js102 kB102 kB+151 B (+0.1%)
    firebase-messaging.js101 kB101 kB+151 B (+0.2%)
    firebase-performance.js119 kB119 kB+151 B (+0.1%)
    firebase-remote-config.js108 kB109 kB+151 B (+0.1%)
    firebase-storage.js145 kB146 kB+772 B (+0.5%)

Test Logs

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Dec 15, 2021

Size Analysis Report 1

This report is too large (1361656 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

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

Copy link
Contributor

@ehsannas ehsannas left a comment

Choose a reason for hiding this comment

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

Added some comments and some questions that a JS newbie doesn't know...

packages/firestore/src/index/ordered_code_writer.ts Outdated Show resolved Hide resolved
*/
private toOrderedBits(val: number): Uint8Array {
const value = doubleToLongBits(val);
const isNegative = (value[0] & 0x80) !== 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why const isNegative = val < 0 is not used? Is it because of the three exceptions listed above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not actually looking at a number that is encoded as a long. Instead, we are looking at the first element of the byte array that is encoded as a number from 0 to 255.

Copy link
Contributor

Choose a reason for hiding this comment

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

that's my question.. wouldn't it be easier to detect negativeness by checking the number (val) rather than checking the byte array (value)?

No action is needed though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are checking whether the bit representation is "negative" not the number itself. Maybe the naming could use some improvement, but this is what the original implementation uses.

The tests fail if we just check if val is negative.

@schmidt-sebastian schmidt-sebastian merged commit 1ef1341 into master Jan 4, 2022
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/numbersonly branch January 4, 2022 18:42
@firebase firebase locked and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants