Reduce number of temporary objects

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Trivial - P5
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: Internal Code
    • None
    • Query Execution
    • Fully Compatible
    • QE 2024-12-09, QE 2024-12-23
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Some code parts use `std::vector::emplace_back(...)` in a non-efficient way.

      Instead of passing the arguments for constructing the object in-place, we are passing a temporary object. The temporary object will then be std::moved into the vector by the `emplace_back` call. This can be improved by just passing the arguments to construct the object in-place.

      For example, instead of

      std::vector<LiteParsedPipeline> liteParsedPipelines;
      ...
      liteParsedPipelines.emplace_back(LiteParsedPipeline(nss, rawPipeline.second));

      we could do

      std::vector<LiteParsedPipeline> liteParsedPipelines;
      ...
      liteParsedPipelines.emplace_back(nss, rawPipeline.second);

      This avoids calling the move ctor in addition to the object creation.

      We have this pattern in several places in the code. We should fix the easy-to-identify ones.

              Assignee:
              Jan Steemann
              Reporter:
              Jan Steemann
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: