Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: speed up unmarshalling by skipping unused unix_fds header #246

Merged
merged 2 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dbus_fast/_private/unmarshaller.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ cdef unsigned int HEADER_SIGNATURE_SIZE
cdef unsigned int LITTLE_ENDIAN
cdef unsigned int BIG_ENDIAN
cdef unsigned int PROTOCOL_VERSION
cdef unsigned int HEADER_UNIX_FDS_IDX
cdef cython.list HEADER_IDX_TO_ARG_NAME

cdef str UINT32_CAST
cdef str INT16_CAST
Expand Down
30 changes: 16 additions & 14 deletions src/dbus_fast/_private/unmarshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,19 @@
EAGAIN = errno.EAGAIN
EWOULDBLOCK = errno.EWOULDBLOCK


HEADER_MESSAGE_ARG_NAME = {
1: "path",
2: "interface",
3: "member",
4: "error_name",
5: "reply_serial",
6: "destination",
7: "sender",
8: "signature",
9: "unix_fds",
}
HEADER_IDX_TO_ARG_NAME = [
"",
"path",
"interface",
"member",
"error_name",
"reply_serial",
"destination",
"sender",
"signature",
"unix_fds",
]
HEADER_UNIX_FDS_IDX = HEADER_IDX_TO_ARG_NAME.index("unix_fds")

_SignatureType = SignatureType
_int = int
Expand Down Expand Up @@ -581,9 +582,11 @@ def _header_fields(self, header_length: _int) -> Dict[str, Any]:
signature_len = buf[self._pos] # byte
o = self._pos + 1
self._pos += signature_len + 2 # one for the byte, one for the '\0'
if field_0 == HEADER_UNIX_FDS_IDX: # defined by self._unix_fds
continue
token_as_int = buf[o]
# Now that we have the token we can read the variant value
key = HEADER_MESSAGE_ARG_NAME[field_0]
key = HEADER_IDX_TO_ARG_NAME[field_0]
# Strings and signatures are the most common types
# so we inline them for performance
if token_as_int == TOKEN_O_AS_INT or token_as_int == TOKEN_S_AS_INT:
Expand Down Expand Up @@ -661,7 +664,6 @@ def _read_body(self) -> None:
self._pos = HEADER_ARRAY_OF_STRUCT_SIGNATURE_POSITION
header_fields = self._header_fields(self._header_len)
self._pos += -self._pos & 7 # align 8
header_fields.pop("unix_fds", None) # defined by self._unix_fds
signature = header_fields.pop("signature", "")
if not self._body_len:
tree = SIGNATURE_TREE_EMPTY
Expand Down