[SERVER-68988] Coverity analysis defect 122770: AUTO_CAUSES_COPY Created: 19/Aug/22  Updated: 29/Oct/23  Resolved: 14/Mar/23

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

Type: Improvement Priority: Minor - P4
Reporter: Coverity Collector User Assignee: Amr Elhelw
Resolution: Fixed Votes: 0
Labels: coverity, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2022-08-19 at 11.22.41 AM.png    
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Sprint: QE 2023-03-06, QE 2023-03-20
Participants:

 Description   

AUTO_CAUSES_COPY

Unnecessary object copies can affect performance. Using the auto keyword without an & causes a copy.
/src/mongo/db/pipeline/document_source_queue.cpp:47: AUTO_CAUSES_COPY 122770 Using the "auto" keyword without an "&" causes the copy of an object of type BSONElement.



 Comments   
Comment by Githook User [ 14/Mar/23 ]

Author:

{'name': 'Amr Elhelw', 'email': 'amr.elhelw@mongodb.com', 'username': 'aelhelw'}

Message: SERVER-68988 Avoid creating copies with auto
Branch: master
https://github.com/mongodb/mongo/commit/2d24e77b9576d0b2f4320810f22c2b81abaaf57f

Comment by Kyle Suarez [ 02/Sep/22 ]

After taking a closer look, we can omit doing CID 122770: we are iterating over BSONElements, and it's efficient to copy them. (They are 16 bytes and therefore are passed via register in all architectures we care about.) I have deleted the screenshot with this CID.

It would still be nice to do CID 123199 as I think we could benefit from not coping the GetNextResult.

Comment by Ana Meza [ 02/Sep/22 ]

Not urgent - but please do if you have time

Comment by Kyle Suarez [ 19/Aug/22 ]

There were multiple AUTO_CAUSES_COPY violations filed so whoever takes this, please sweep through the file.

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