In a recent change to BSONIteratorSorted, we changed from using a raw array to a vector. In doing so, we pre-allocate the space for that vector, tapping into the nFields BSONObj function to get the number of fields. This function scans the BSONObj. We then, later, scan the BSONObj again to fill in the vector.
It's possible to forgo a scan and not preallocate space in the vector. But it's a tradeoff. What has worse performance, scanning a BSONObj or constructing a vector item-by-item?
We should benchmark this and see if it's worth changing.
Also, we use .at() which is strictly worse performance than [] to access items.
ivan.fefer@mongodb.com gets credit for finding this!
- is related to
-
SERVER-86146 Fix UBSAN errors seen with new TCMalloc
- Closed
-
SERVER-86267 Investigate why a dynamically-allocated array of structs trips UBSAN with the new TCMalloc
- Closed