Reduce per-document overhead in PlanExecutorImpl::_getNextImpl

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.1.0-rc0, 9.0.0-rc3
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • v9.0
    • 200
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Overview

      PlanExecutorImpl::_getNextImpl() runs once per returned document. Profiling found four small pieces of work in that loop that are loop-invariant or avoidable.

      Scope of Work

      * plan_executor_impl.cpp — guard getOwned() on isOwned() and use the rvalue overload, so an already-owned document is not copied
      * plan_executor_impl.h/.cpp — cache the recordId metadata dependency at construction instead of reading CanonicalQuery::metadataDeps() per document
      * plan_executor_impl.cpp — call swap unqualified so ADL selects mongo::swap instead of the generic std::swap template, which expands to three intrusive_ptr moves each ending in a conditional refcount release
      * document_internal.h — in DocumentStorage::isOwned(), test the single-load isOwned() before isEmptyPrototype(), which is false for every non-empty document

      Notes

      Measured on aarch64 against $lookup -> $match -> $addFields. The profile is flat and _getNextImpl is ~0.73% of cycles, so each change is worth a fraction of a percent; they are grouped because they share a call site, not because any one is significant alone.

      Acceptance Criteria

      * No change in query results or metadata propagation
      * Existing query correctness suites pass

            Assignee:
            Catalin Sumanaru
            Reporter:
            Catalin Sumanaru
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: