-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Service Arch
-
Fully Compatible
-
v8.0
-
Service Arch 2024-04-01, Service Arch 2024-04-15, Service Arch 2024-04-29, Programmability 2024-05-27
-
41
The code generated for OplogEntryBase takes an OpTime and calls toBSON(), which constructs its own BSONOBjBuilder and allocates its own memory, rather than re-using the Builder in the calling function.
void OplogEntryBase::serialize(BSONObjBuilder* builder) const { _hasMembers.required(); /// snipped if (_donorOpTime) { const BSONObj localObject = (*_donorOpTime).toBSON(); // why not reuse the builder? builder->append(kDonorOpTimeFieldName, localObject); }
This is very wasteful and appears to be happening in all of our IDL-generated files that have OpTime members.
This is true for non-optional OpTimes also:
void ElectionParticipantMetrics::serialize(BSONObjBuilder* builder) const { _hasMembers.required(); // snipped { const BSONObj localObject = _lastWrittenOpTimeAtElection.toBSON(); builder->append(kLastWrittenOpTimeAtElectionFieldName, localObject); }