-
Notifications
You must be signed in to change notification settings - Fork 937
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
Conversation
Binary Size ReportAffected SDKs
Test Logs |
2fa771a
to
60bd5a3
Compare
There was a problem hiding this 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' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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' |
There was a problem hiding this comment.
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.
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.