Skip to content

Drop SortedSet from FieldMask #2999

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

Merged
merged 2 commits into from
May 1, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

I would like to not use SortedSet in FieldMask since the Rest Wrapper API ideally does not pull in our custom Red Black Tree. FieldMasks are used in any update/set(merge:true) call.

Right now, I have a debug assert that makes sure FieldMasks only contain unique fields. This means we have to validate this as we turn user data into FieldMasks. We could also strip duplicated fields in the FieldMask constructor.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 29, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (a6e9d5b) Head (dc4f545) Diff
    browser 247 kB 247 kB +38 B (+0.0%)
    esm2017 193 kB 193 kB -6 B (-0.0%)
    main 487 kB 487 kB +9 B (+0.0%)
    module 245 kB 245 kB +19 B (+0.0%)
  • @firebase/firestore/memory

    Type Base (a6e9d5b) Head (dc4f545) Diff
    browser 188 kB 188 kB +28 B (+0.0%)
    esm2017 148 kB 148 kB +7 B (+0.0%)
    main 364 kB 364 kB +9 B (+0.0%)
    module 186 kB 186 kB +8 B (+0.0%)
  • firebase

    Type Base (a6e9d5b) Head (dc4f545) Diff
    firebase-firestore.js 289 kB 289 kB -6 B (-0.0%)
    firebase-firestore.memory.js 231 kB 231 kB -6 B (-0.0%)
    firebase.js 822 kB 822 kB -6 B (-0.0%)

Test Logs

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/arraybackedfieldvalues branch from 2fa771a to 60bd5a3 Compare April 29, 2020 23:54
Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

LGTM. The only potential issue that comes to mind is O(log(n)) operations of SortedSet now become O(n). Can you confirm that this will not be a performance issue for users?

fields.sort(FieldPath.comparator);
debugAssert(
!fields.some((v, i) => i !== 0 && v.isEqual(fields[i - 1])),
'FieldMask contains fields that are not unique'
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be helpful to include the name of the repeated field in the message. Consider adding this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't think of a clean way to do this, so I added an ugly way. Done.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

There are three code paths that generated FieldMasks:

  • A field mask is provided explicitly via mergeFields. In this case, we turn an O(n log n) operation into O(n2).
  • A field mask update is provided in an update vargargs call. In this case, we also turn an O(n log n) operation into O(n2).
  • A field mask is generated from an ObjectValue or from a DocumentData object. In this case, the creation of the field mask is now O(n), but with the additional sort it becomes O(n log n), which is the same as before.

I think we are ok here since cases 1 and 2 should not deal with huge field masks.

fields.sort(FieldPath.comparator);
debugAssert(
!fields.some((v, i) => i !== 0 && v.isEqual(fields[i - 1])),
'FieldMask contains fields that are not unique'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't think of a clean way to do this, so I added an ugly way. Done.

@schmidt-sebastian schmidt-sebastian merged commit e03614c into master May 1, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/arraybackedfieldvalues branch May 1, 2020 01:24
scottcrossen pushed a commit that referenced this pull request May 4, 2020
@firebase firebase locked and limited conversation to collaborators Jun 1, 2020
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.

3 participants