-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Server Programmability
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The code that is generated when one specifies a type with serialisation type of 'any' looks like this:
BSONArrayBuilder arrayBuilder(builder->subarrayStart(kWriteErrorsFieldName));
for (const auto& item : _writeErrors.get()) {
const BSONObj localObject = item.serialize();
arrayBuilder.append(localObject);
}
This means that the serialiser method returns a free-standing BSONObject, which is then copied into the main builder.
It would be more efficient if the serialiser generated looked like this in order to avoid the data copy:
BSONArrayBuilder arrayBuilder(builder->subarrayStart(kWriteErrorsFieldName));
for (const auto& item : _writeErrors.get()) {
item.serialize(arrayBuilder.subObjectStart(localObject));
}
This would require all places that use serialisation type of any currently to be changed so that their serialise method takes a BSONObjBuilder instead of returning BSONObj.