Skip to content

Commit

Permalink
feat: speed up unmarshall performance (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 4, 2022
1 parent 4ea6eae commit f38e08f
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 148 deletions.
9 changes: 8 additions & 1 deletion bench/unmarshall.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)


stream = io.BytesIO(bytes.fromhex(bluez_rssi_message))

unmarshaller = Unmarshaller(stream)


def unmarhsall_bluez_rssi_message():
Unmarshaller(io.BytesIO(bytes.fromhex(bluez_rssi_message))).unmarshall()
stream.seek(0)
unmarshaller.reset()
unmarshaller.unmarshall()


count = 1000000
Expand Down
9 changes: 8 additions & 1 deletion bench/unmarshall_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@
)


stream = io.BytesIO(bluez_properties_message)

unmarshaller = Unmarshaller(stream)


def unmarhsall_bluez_rssi_message():
Unmarshaller(io.BytesIO(bluez_properties_message)).unmarshall()
stream.seek(0)
unmarshaller.reset()
unmarshaller.unmarshall()


count = 1000000
Expand Down
32 changes: 19 additions & 13 deletions src/dbus_fast/_private/unmarshaller.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@ from ..signature import SignatureType
cdef unsigned int UINT32_SIZE
cdef unsigned int HEADER_ARRAY_OF_STRUCT_SIGNATURE_POSITION
cdef unsigned int HEADER_SIGNATURE_SIZE
cdef unsigned int LITTLE_ENDIAN
cdef unsigned int BIG_ENDIAN
cdef str UINT32_CAST
cdef object UINT32_SIGNATURE

cdef class Unmarshaller:

cdef object unix_fds
cdef bytearray buf
cdef object view
cdef unsigned int pos
cdef object stream
cdef object sock
cdef object _unix_fds
cdef bytearray _buf
cdef object _view
cdef unsigned int _pos
cdef object _stream
cdef object _sock
cdef object _message
cdef object readers
cdef unsigned int body_len
cdef unsigned int serial
cdef unsigned int header_len
cdef object message_type
cdef object flag
cdef unsigned int msg_len
cdef object _readers
cdef unsigned int _body_len
cdef unsigned int _serial
cdef unsigned int _header_len
cdef unsigned int _message_type
cdef unsigned int _flag
cdef unsigned int _msg_len
cdef object _uint32_unpack

cpdef reset(self)

@cython.locals(
start_len=cython.ulong,
Expand Down Expand Up @@ -56,6 +61,7 @@ cdef class Unmarshaller:
@cython.locals(
endian=cython.uint,
protocol_version=cython.uint,
can_cast=cython.bint
)
cpdef _read_header(self)

Expand Down
Loading

0 comments on commit f38e08f

Please sign in to comment.