Skip to content

Firestore: Remove copies in FieldValueInternal to reduce global refs consumption. #1111

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
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firestore/src/android/field_value_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ FieldValueInternal::FieldValueInternal(GeoPoint value)
object_ = GeoPointInternal::Create(env, value);
}

FieldValueInternal::FieldValueInternal(std::vector<FieldValue> value)
FieldValueInternal::FieldValueInternal(const std::vector<FieldValue>& value)
: cached_type_(Type::kArray) {
Env env = GetEnv();
Local<ArrayList> list = ArrayList::Create(env, value.size());
Expand All @@ -167,7 +167,7 @@ FieldValueInternal::FieldValueInternal(std::vector<FieldValue> value)
object_ = list;
}

FieldValueInternal::FieldValueInternal(MapFieldValue value)
FieldValueInternal::FieldValueInternal(const MapFieldValue& value)
: cached_type_(Type::kMap) {
Env env = GetEnv();
Local<HashMap> map = HashMap::Create(env);
Expand Down
10 changes: 8 additions & 2 deletions firestore/src/android/field_value_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ class FieldValueInternal {
FieldValueInternal(const uint8_t* value, size_t size);
explicit FieldValueInternal(DocumentReference value);
explicit FieldValueInternal(GeoPoint value);
explicit FieldValueInternal(std::vector<FieldValue> value);
explicit FieldValueInternal(MapFieldValue value);
// Deviate from the iOS signatures of the following two constructors. The iOS
// versions take values into which the caller moves, to elide a copy. In
// Android, this actually *costs* an extra copy when calling from
// `DocumentReferenceInternal::Set()`, doubling the number of global
// references needed. Using const references in Android avoids this extra,
// costly copy (https://github.com/firebase/quickstart-unity/issues/1303).
explicit FieldValueInternal(const std::vector<FieldValue>& value);
explicit FieldValueInternal(const MapFieldValue& value);

Type type() const;

Expand Down
6 changes: 6 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,12 @@ workflow use only during the development of your app, not for publicly shipping
code.

## Release Notes
### Upcoming
- Changes
- Firestore (Android): Reduce the number of JNI global references consumed
when creating or updating documents
([#1111](https://github.com/firebase/firebase-cpp-sdk/pull/1111)).

### 10.0.0
- Changes
- General (Android): Update to Firebase Android BoM version 31.0.0.
Expand Down