Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2021

Operation.createMsgWireMessage() allocates memory inefficiently

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.11.0
    • Affects Version/s: 1.5.2
    • Component/s: None
    • Labels:
      None

      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.

       

       

            Assignee:
            qingyang.hu@mongodb.com Qingyang Hu
            Reporter:
            tim.fogarty@mongodb.com Tim Fogarty
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: