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