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

Avoid repeated string creation in applyCommand_inlock

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: Replication
    • None
    • Query Execution
    • Fully Compatible
    • QE 2025-02-17
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      In oplog.cpp we currently create a vector of {{std::string}}s for every command that is applied.
      While the strings are short and can likely benefit from the short value optimization that are present in std::string implementations, creating them and allocating a new instance of std::vector to hold these strings in every invocation of the function seems to be unnecessary work.
      Additionally, we only need these strings if the oplog application mode is kInitialSync

      Furthermore, if the oplog application mode is kInitialSync , we currently implicit convert the oplog command name into an std::string only to compare it with the entries in the vector here.

      To improve this, we could move the vector outside of the function, so it is created only once. Even better would be to make it an std::array to avoid the heap memory of a vector altogether. Finally, we can change it from a container of {{std::string}}s to a container of {{StringData}}s.

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

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None