-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Storage
-
None
-
Query Execution
-
QE 2026-08-03, QE 2026-08-17
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Removes per-field hash lookups from three `Document` operations that do not need them:
- `DocumentStorageIterator::shouldSkipDeleted()` previously called `DocumentStorage::findFieldInCache()` for every field of the backing BSON, computing an absl hash of the field name (or scanning the cache linearly for small documents) even when the cache held no fields at all. It now returns early when the cache is empty. The check is per- field rather than hoisted out of the loop, because `get()` can populate the cache part-way through an iteration.
- `DocumentStorage::computeSize()` moves out of line into document.cpp and gains a fast path for unmodified storage, counting non-metadata fields directly from the backing BSON instead of constructing a `DocumentStorageIterator`. This works because an unmodified storage's cache contains only `kCached` mirrors of fields still present in the `_bson`, but nothing inserted and nothing logically removed. `constructInCache()` is the sole caller that saves and restores `_modified` around `appendField()`.
- `Document::empty()` gains a matching fast path, answering from `BSONObj::isEmpty()` via the new `DocumentStorage::bsonObjIsEmpty()` accessor rather than building a full iterator. Documents whose BSON carries metadata are excluded from this path, since metadata fields are hidden from iteration but still counted by `isEmpty()`.
No behavior change is intended. The fast paths are gated on `_modified` and `_bsonHasMetadata`, so anything that has been mutated or that carries metadata takes the previous code path.