Skip to content

Commit afa0cdd

Browse files
authored
Firestore: Remove copies in FieldValueInternal to reduce global refs consumption. (#1111)
1 parent 07c75bc commit afa0cdd

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

firestore/src/android/field_value_android.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ FieldValueInternal::FieldValueInternal(GeoPoint value)
156156
object_ = GeoPointInternal::Create(env, value);
157157
}
158158

159-
FieldValueInternal::FieldValueInternal(std::vector<FieldValue> value)
159+
FieldValueInternal::FieldValueInternal(const std::vector<FieldValue>& value)
160160
: cached_type_(Type::kArray) {
161161
Env env = GetEnv();
162162
Local<ArrayList> list = ArrayList::Create(env, value.size());
@@ -167,7 +167,7 @@ FieldValueInternal::FieldValueInternal(std::vector<FieldValue> value)
167167
object_ = list;
168168
}
169169

170-
FieldValueInternal::FieldValueInternal(MapFieldValue value)
170+
FieldValueInternal::FieldValueInternal(const MapFieldValue& value)
171171
: cached_type_(Type::kMap) {
172172
Env env = GetEnv();
173173
Local<HashMap> map = HashMap::Create(env);

firestore/src/android/field_value_android.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ class FieldValueInternal {
6464
FieldValueInternal(const uint8_t* value, size_t size);
6565
explicit FieldValueInternal(DocumentReference value);
6666
explicit FieldValueInternal(GeoPoint value);
67-
explicit FieldValueInternal(std::vector<FieldValue> value);
68-
explicit FieldValueInternal(MapFieldValue value);
67+
// Deviate from the iOS signatures of the following two constructors. The iOS
68+
// versions take values into which the caller moves, to elide a copy. In
69+
// Android, this actually *costs* an extra copy when calling from
70+
// `DocumentReferenceInternal::Set()`, doubling the number of global
71+
// references needed. Using const references in Android avoids this extra,
72+
// costly copy (https://github.com/firebase/quickstart-unity/issues/1303).
73+
explicit FieldValueInternal(const std::vector<FieldValue>& value);
74+
explicit FieldValueInternal(const MapFieldValue& value);
6975

7076
Type type() const;
7177

release_build_files/readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ workflow use only during the development of your app, not for publicly shipping
634634
code.
635635

636636
## Release Notes
637+
### Upcoming
638+
- Changes
639+
- Firestore (Android): Reduce the number of JNI global references consumed
640+
when creating or updating documents
641+
([#1111](https://github.com/firebase/firebase-cpp-sdk/pull/1111)).
642+
637643
### 10.0.0
638644
- Changes
639645
- General (Android): Update to Firebase Android BoM version 31.0.0.

0 commit comments

Comments
 (0)