Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1559

Avoid multiple levels of byte join()s in message/bson module

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Internal
    • Labels:
      None

      The message module __pack_message function requires us to copy the encoded command document twice. First to generate the "data" and second to generate the full wire protocol message.

      To reduce the number of data copies, we could add _pack_message_parts(operation, msg_parts) that accepts a list of message parts. It could perform a single b"".join() instead of the two levels of copies that are required by _pack_message

      Another option would be to never join the byte strings in the first place. We could
      instead, pass a list of byte strings to send over the network:

      msg_parts = [msg_header, msg_part2, msg_part3, ...]
      for part in msg_parts:
          sock.send(part)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: