summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Boros <ian.boros@mongodb.com>2020-01-08 01:49:29 +0000
committerevergreen <evergreen@mongodb.com>2020-01-08 01:49:29 +0000
commit7e675af0b642d6a84d770d083045908aa0459f7d (patch)
tree631a0c6e5ea96b3ebb5b44f50da25f0304f07bdf
parent1a4fb8445254a73adabad98eafbb5a8fc0e2ae05 (diff)
downloadmongo-7e675af0b642d6a84d770d083045908aa0459f7d.tar.gz
SERVER-45192 don't allocate during WSM::clear
-rw-r--r--src/mongo/db/exec/document_value/document.h4
-rw-r--r--src/mongo/db/exec/working_set.cpp10
2 files changed, 13 insertions, 1 deletions
diff --git a/src/mongo/db/exec/document_value/document.h b/src/mongo/db/exec/document_value/document.h
index 5b9d953b287..978d008cae0 100644
--- a/src/mongo/db/exec/document_value/document.h
+++ b/src/mongo/db/exec/document_value/document.h
@@ -334,6 +334,10 @@ public:
return _storage ? _storage->isModified() : false;
}
+ bool hasExclusivelyOwnedStorage() const {
+ return _storage && !_storage->isShared();
+ }
+
/// only for testing
const void* getPtr() const {
return _storage.get();
diff --git a/src/mongo/db/exec/working_set.cpp b/src/mongo/db/exec/working_set.cpp
index 94e564f8cf2..6529df45b07 100644
--- a/src/mongo/db/exec/working_set.cpp
+++ b/src/mongo/db/exec/working_set.cpp
@@ -113,7 +113,15 @@ WorkingSetID WorkingSet::emplace(WorkingSetMember&& wsm) {
void WorkingSetMember::clear() {
_metadata = DocumentMetadataFields{};
keyData.clear();
- resetDocument(SnapshotId(), BSONObj());
+ if (doc.value().hasExclusivelyOwnedStorage()) {
+ // Reset the document to point to an empty BSON, which will preserve its underlying
+ // DocumentStorage for future users of this WSM.
+ resetDocument(SnapshotId(), BSONObj());
+ } else {
+ // If the Document doesn't exclusively own its storage, don't do anything. Attempting to
+ // assign it a value (even an empty one) would result in an allocation, which we don't want
+ // here, since this function is very much on the hot path.
+ }
_state = WorkingSetMember::INVALID;
}