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

Operation.createMsgWireMessage() allocates memory inefficiently

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor - P4 Minor - P4
    • 1.11.0
    • 1.5.2
    • None
    • None

    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.

       

       

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: