-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Server Programmability
-
None
-
None
-
None
-
None
-
None
-
None
-
None
BSONElement is an unowned view of one element of a BSONObj. This makes it difficult to use in another data structure, because whoever holds a BSONElement also has to keep the original BSON alive somehow.
Instead I wish BSONElement would contribute to the refcount of the underlying BSON. Or, it could be a separate type like SharedBSONElement. Then when I embed a SharedBSONElement in some larger data structure (MatchExpression or IDL types maybe), whoever holds that larger data structure isn't forced to separately manage the lifetime of the original BSONObj.
SharedBSONElement would not create a new allocation: it would contribute to the refcount of the same underlying buffer.
The same thing can apply to BSONObj. Today when you want to extract a subdocument from a larger BSONObj, your choices are:
- allocate a new copy using BSONObj::getOwned()
- avoid a copy but explicitly manage the lifetime of the original BSON
This leads to workarounds like SERVER-87277 where we want to retain the buffer and view a slice of it, but because BSONObj doesn't support this we end up juggling two separate BSONObj instances (one owned, one unowned).
- is depended on by
-
SERVER-101544 Investigate if DocumentSourceMatch::joinMatchWith can operate over MatchExpression instead of BSONObj
-
- Blocked
-
- is related to
-
SERVER-90372 Use document views rather than making copies when parsing find requests
-
- Backlog
-
- related to
-
SERVER-87277 Reduce CanonicalQuery creation overhead by avoiding BSONObj creation
-
- Closed
-