Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-88423

OpTimes in IDL serialization should reuse BSONObjBuilder buffer

    • 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);
          }
      

            Assignee:
            blake.oler@mongodb.com Blake Oler
            Reporter:
            louis.williams@mongodb.com Louis Williams
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: