Avoid calling _changeStreamCursor->begin() unnecessarily

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Atlas Streams
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      cursor::begin() just calls into iterator::operator++() if the change stream has started [1], which means in change_stream_source_opeator.cpp code we could save a few places where we unnecessarily calls begin() or checking _it == _changeStreamCursor->end() [2]. Instead the logic could be simplified as

      ++_it;

      if (_it != _changeStreamCursor->end())

      {   \{process data}

      } else

      {   \{idle}

      }

      [1] https://github.com/mongodb/mongo-cxx-driver/blob/master/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/change_stream.cpp#L46

      [2]https://github.com/10gen/mongo/blob/master/src/mongo/db/modules/enterprise/src/streams/exec/change_stream_source_operator.cpp#L1135C9-L1135C22

      https://github.com/10gen/mongo/blob/master/src/mongo/db/modules/enterprise/src/streams/exec/change_stream_source_operator.cpp#L1160

            Assignee:
            Unassigned
            Reporter:
            Jason Qiu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: