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

Reduce copies inside resharding_oplog_fetcher.cpp

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Query Execution
    • Fully Compatible
    • QE 2024-11-11

      SERVER-96561 introduced functionality to insert oplog entries in batches.
      There are two small opportunities to improve the performance of the initial implementation:

      • we are currently creating temporary InsertStatement objects, which we could avoid.
      • instead of copying a vector of InsertStatments into the outer vector of InsertStatements, we could move it.

      Suggested change (based on original code introduced in SERVER-96561):

      diff --git a/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp b/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
      index 5a401eb64d9..202cc288600 100644
      --- a/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
      +++ b/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
      @@ -148,12 +147,12 @@ std::vector<std::vector<InsertStatement>> getOplogInsertBatches(
                   } else if (totalBytes + currentBytes > maxBytes) {
                       break;
                   }
      -            insertBatch.emplace_back(InsertStatement(currentDoc));
      +            insertBatch.emplace_back(currentDoc);
                   totalBytes += currentBytes;
               } while (++currentIndex < aggregateBatch.size() && insertBatch.size() < maxOperations &&
                        totalBytes < maxBytes);
      
      -        insertBatches.push_back(insertBatch);
      +        insertBatches.push_back(std::move(insertBatch));
           }
      
           return insertBatches;
      

            Assignee:
            jan.steemann@mongodb.com Jan Steemann
            Reporter:
            jan.steemann@mongodb.com Jan Steemann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: