Skip to content

Migrate FieldValue to Protobuf #8124

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 60 commits into from
Jul 22, 2021
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented May 20, 2021

This PR removes the FieldValue classes and updates the client to directly use Protobuf messages internally. It aligns the iOS client with the Web and Android client.

CPU time benchmark On iPhone 8:

Benchmark Name Branch (us) Master (us) Speedup (x)
BM_QueryIndexFree/0/1 7.68 18.6 2.42
BM_QueryIndexFree/1/1 12.3 27.7 2.25
BM_QueryIndexFree/1/10 13 28.7 2.21
BM_QueryIndexFree/10/10 22.4 25.9 1.16
BM_QueryIndexFree/1/100 11.9 29.2 2.45
BM_QueryIndexFree/100/100 8.87 24.3 2.74
BM_QueryIndexFree/1/1000 18.7 29 1.55
BM_QueryIndexFree/10/1000 17.8 28.9 1.62
BM_QueryIndexFree/100/1000 9.89 36.9 3.73
BM_QueryIndexFree/1000/1000 21.1 46.4 2.20
BM_QueryMatching/0/1 12.8 40.5 3.16
BM_QueryMatching/1/1 18.7 41.2 2.20
BM_QueryMatching/1/10 35.3 45.9 1.30
BM_QueryMatching/10/10 53.4 59.4 1.11
BM_QueryMatching/1/100 63.4 108 1.70
BM_QueryMatching/100/100 44.5 127 2.85
BM_QueryMatching/1/1000 60.3 251 4.16
BM_QueryMatching/10/1000 73.3 181 2.47
BM_QueryMatching/100/1000 24.7 149 6.03
BM_QueryMatching/1000/1000 27.8 150 5.40
BM_QueryAll/1 21 32.2 1.53
BM_QueryAll/10 24.5 34.5 1.41
BM_QueryAll/100 9.41 37.9 4.03
BM_QueryAll/1000 17.3 Out of memory Inf

Full results (internal): go/fieldvalue-benchmark

XCode's Leak Detector does not detect any leaks with this PR when used in FriendlyEats.

schmidt-sebastian and others added 30 commits March 12, 2021 12:42
* Run migration to rewrite canonical IDs

* Be more thorough.

* Feedback.

* Fix lint error
Should be compared to Android. These classes now use Document as the new immutable document type
case TypeOrder::kString:
return nanopb::MakeStringView(lhs.string_value) ==
nanopb::MakeStringView(rhs.string_value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case TypeOrder::kBlob:
return CompareBlobs(lhs, rhs) == ComparisonResult::Same;

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

case TypeOrder::kReference:
return nanopb::MakeStringView(lhs.reference_value) ==
nanopb::MakeStringView(rhs.reference_value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

case TypeOrder::kGeoPoint:
return lhs.geo_point_value.latitude == rhs.geo_point_value.latitude &&
lhs.geo_point_value.longitude == rhs.geo_point_value.longitude;

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case TypeOrder::kArray:
return ArrayEquals(lhs.array_value, rhs.array_value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

Comment on lines +380 to +382

default:
HARD_FAIL("Invalid type value: %s", left_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

switch (value.which_value_type) {
case google_firestore_v1_Value_null_value_tag:
return "null";

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_boolean_value_tag:
return value.boolean_value ? "true" : "false";

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_integer_value_tag:
return std::to_string(value.integer_value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_double_value_tag:
return absl::StrFormat("%.1f", value.double_value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_timestamp_value_tag:
return CanonifyTimestamp(value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_string_value_tag:
return nanopb::MakeString(value.string_value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_bytes_value_tag:
return CanonifyBlob(value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_reference_value_tag:
return CanonifyReference(value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_geo_point_value_tag:
return CanonifyGeoPoint(value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.


case google_firestore_v1_Value_array_value_tag:
return CanonifyArray(value.array_value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

Comment on lines +478 to +481
}

default:
HARD_FAIL("Invalid type value: %s", value.which_value_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

Comment on lines +485 to +487
std::string CanonicalId(const google_firestore_v1_ArrayValue& value) {
return CanonifyArray(value);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

source.string_value->size)
: nullptr;
break;

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

target->reference_value = nanopb::MakeBytesArray(
source.reference_value->bytes, source.reference_value->size);
break;

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

source.bytes_value->size)
: nullptr;
break;

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

*DeepClone(source.array_value.values[i]).release();
}
break;

Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

MaybeDocument VerifyMutation::Rep::ApplyToRemoteDocument(
const absl::optional<MaybeDocument>&, const MutationResult&) const {
void VerifyMutation::Rep::ApplyToRemoteDocument(MutableDocument&,
const MutationResult&) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

absl::optional<MaybeDocument> VerifyMutation::Rep::ApplyToLocalView(
const absl::optional<MaybeDocument>&, const Timestamp&) const {
void VerifyMutation::Rep::ApplyToLocalView(MutableDocument&,
const Timestamp&) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

Comment on lines +167 to +168
return FieldFilter::Create({}, {},
MakeSharedMessage(google_firestore_v1_Value{}));
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

Comment on lines +495 to +501
// TODO(rsgowman): implement.
// In particular, since this statement isn't hit, it implies a missing
// test for UnknownDocument. However, we'll defer that until after
// nanopb-master is merged to master.
abort();
} else {
FAIL() << "We somehow created an invalid model object";
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

Comment on lines +164 to +169
Message<google_firestore_v1_MapValue> value) {
Message<google_firestore_v1_Value> result;
result->which_value_type = google_firestore_v1_Value_map_value_tag;
result->map_value = *value.release();
return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

Comment on lines +179 to +180
Message<google_firestore_v1_Value> Value(const model::ObjectValue& value) {
return DeepClone(value.Get());
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

nanopb::MakeStringView(value.string_value) != kDeleteSentinel) {
object_value.Set(field_path, DeepClone(value));
} else if (nanopb::MakeStringView(value.string_value) == kDeleteSentinel) {
object_value.Delete(field_path);
Copy link
Contributor

Choose a reason for hiding this comment

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

Incremental code coverage report

Tests for New code lines are not detected in FirebaseFirestore-iOS, please add tests on highlighted lines.

@firebase firebase locked and limited conversation to collaborators Aug 22, 2021
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.

4 participants