-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Server Programmability
RemoteCommandRequest implements an explicit conversion to OpMsgRequest that calls through to OpMsgRequestBuilder::create. create will make a copy of the request BSONObj if it is not the sole owner of it, which will always be the case due to the const-ness of the operator not allowing for moving out of this. As a result, all internal operations make a copy of their request, regardless of whether it is actually necessary.
We should change the way we convert between RemoteCommandRequest and OpMsgRequest to ensure no unnecessary copies are made, at minimum. We should also explore more generally if we can make better use of IDL-generated command requests serialize method, which serializes directly to an OpMsgRequest. This guarantees no unneeded copies are made, while also supporting the usage of document sequences.