Skip to content

Commit

Permalink
Major performance improvements
Browse files Browse the repository at this point in the history
Replaced byte string concatenation with bytearray extend functions.
This is ~50 times faster! (See also python-ivi#8)
  • Loading branch information
eltos committed Mar 9, 2017
1 parent 6852d3c commit 2c7c60a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions vxi11/rpc.py
Expand Up @@ -232,21 +232,20 @@ def recvfrag(sock):
x = struct.unpack(">I", header[0:4])[0]
last = ((x & 0x80000000) != 0)
n = int(x & 0x7fffffff)
frag = b''
while n > 0:
buf = sock.recv(n)
frag = bytearray()
while len(frag) < n:
buf = sock.recv(n - len(frag))
if not buf: raise EOFError
n = n - len(buf)
frag = frag + buf
frag.extend(buf)
return last, frag

def recvrecord(sock):
record = b''
record = bytearray()
last = 0
while not last:
last, frag = recvfrag(sock)
record = record + frag
return record
record.extend(frag)
return bytes(record)


# Client using TCP to a specific port
Expand Down

0 comments on commit 2c7c60a

Please sign in to comment.