[GODRIVER-2021] Operation.createMsgWireMessage() allocates memory inefficiently Created: 23/May/21  Updated: 28/Oct/23  Resolved: 08/Sep/22

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: 1.5.2
Fix Version/s: 1.11.0

Type: Improvement Priority: Minor - P4
Reporter: Tim Fogarty Assignee: Qingyang Hu
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-1670 Use buffer pooling and copying return... Closed
Epic Link: Reduce Allocations
Quarter: FY23Q2, FY23Q3

 Description   

This loop in Operation.createMsgWireMessage() is inefficient:

for _, doc := range op.Batches.Current {
    dst = append(dst, doc...)
} 

since dst is not at the required cap before the loop, it causes multiple allocations and the final cap of dst can be up to 2x larger than needed.

Calculating the total length of batches in op.Batches.Current and resizing dst before the loop would be more efficient.

 

 



 Comments   
Comment by Githook User [ 07/Sep/22 ]

Author:

{'name': 'Qingyang Hu', 'email': '103950869+qingyang-hu@users.noreply.github.com', 'username': 'qingyang-hu'}

Message: GODRIVER-2021 Use pooling to reduce memory allocation. (#1053)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/988abba6f907f562fdb944577f956cb7cd794b37

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