[SERVER-78081] Optimize memory footprint of optional fields in query_stats::KeyGenerators Created: 14/Jun/23  Updated: 29/Oct/23  Resolved: 18/Jul/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Charlie Swanson Assignee: William Qian
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Problem/Incident
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Sprint: QO 2023-06-26, QO 2023-07-10, QO 2023-07-24
Participants:
Linked BF Score: 164

 Description   

I was reading over this page after I was surprised by the size of some of these objects: https://www.boost.org/doc/libs/1_59_0/libs/optional/doc/html/boost_optional/tutorial/performance_considerations.html

 

It is probably worth doing some of that bool _has_allow_partial_results pattern rather than all the boost::optionals we have here: https://github.com/mongodb/mongo/blob/cf00278a5230148eaf71c04df84f6c6de77decee/src/mongo/db/query/query_stats_find_key_generator.h#L91



 Comments   
Comment by Githook User [ 13/Jul/23 ]

Author:

{'name': 'William Qian', 'email': 'william.qian@mongodb.com', 'username': 'wqian94'}

Message: SERVER-78081 Refactor key generator members to reduce object size
Branch: master
https://github.com/mongodb/mongo/commit/b1567c946c31f6232303cb81faab01426d914f81

Comment by Githook User [ 12/Jul/23 ]

Author:

{'name': 'liubov.molchanova', 'email': 'liubov.molchanova@mongodb.com', 'username': 'liubov-molchanova'}

Message: Revert "SERVER-78081 Refactor key generator members to reduce object size"

This reverts commit 41a8b3b19f57681424bbdbe98afdb307e1d58e46.
Branch: master
https://github.com/mongodb/mongo/commit/e8972a252d45877c7d0f4f5fd65d4596cf34d9ef

Comment by Githook User [ 11/Jul/23 ]

Author:

{'name': 'William Qian', 'email': 'william.qian@mongodb.com', 'username': 'wqian94'}

Message: SERVER-78081 Refactor key generator members to reduce object size
Branch: master
https://github.com/mongodb/mongo/commit/41a8b3b19f57681424bbdbe98afdb307e1d58e46

Comment by William Qian [ 21/Jun/23 ]

We could also consider using bit fields. Something like

BSONObj _readConcern;
int64_t batchSize;
int32_t maxTimeNS;
bool _allowPartialResults;
bool _noCursorTimeout;

struct {
    bool readConcern : 1 = false;
    bool allowPartialResults : 1 = false;
    bool noCursorTimeout : 1 = false;
    bool maxTimeNS : 1 = false;
    bool batchSize : 1 = false;
} hasField;

should do the trick. `hasfield` is 1B, so this should be `sizeof (BSONObj) + 16` bytes. (`_allowPartialResults`, `_noCursorTimeout`, and `hasField` all have alignments and sizes of 1.)

Generated at Thu Feb 08 06:37:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.