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

OpTimes in IDL serialization should reuse BSONObjBuilder buffer

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Service Arch
    • v8.0
    • Service Arch 2024-04-01, Service Arch 2024-04-15, Service Arch 2024-04-29, Service Arch 2024-05-13
    • 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: