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

🔥 message mod API improvements #439

Merged
merged 21 commits into from
Aug 16, 2023
Merged

Conversation

zeenix
Copy link
Contributor

@zeenix zeenix commented Aug 11, 2023

Many improvements to message module API, improving the ergonomics and performance.

Among other things, it drops/hides a lot of low-level API that IMO we should have never provided. In my defense, I was new to Rust when I wrote this code. :)


Zeeshan Ali Khan on behalf of MBition GmbH.

Provider Information.

This variant is never constructed by us. When we encounter invalid field
code, we throw an error.
Seriously doubt anyone uses this and this will also allow us to drop
`FieldCode::Invalid` in the following commit.
A message with an invalid field code will just fail to deserialize so we
don't need to represent this state.
Seriously doubt anyone uses this and this will also allow us to drop
`message::Type::Invalid` in the following commit.
An invalid message will just fail to deserialize so we don't need to
represent this state.
We'll be using these to avoid having to deserialize header and individual
fields repeatedly.
As it is now based on the internal fields cache and doesn't involve
deserializing the header.
We now construct the Header from fields cache and primary header clone.
This variant is never constructed anymore and hence useless.

We could just deprecate it only but the chances of someone using this in
client code are very low so let's not bother.
We now construct the fields from the cache.
Since we construct the fields from the cache.
Since we construct the header from the cache now.
Since we either construct the header from the cache now or deserialize
from raw bytes and the deserialization will fail if the message has
fields with incorrect codes (the only possible issue here).
They'll be deprecated in a following commit.
Not only is the performance of the direct fields getters no longer much
worse than the getting the fields through the header, but also field
getters on the header are much faster the that of Message.

Moreover, I've ideas on how to make the header getter even faster.
I don't see users having much need for this and we're about to make
`Field*` API private.
We don't need this method internally, doubt anyone uses it and we're
about to turn Field* API private anyway.
We don't need this method internally, doubt anyone uses it and we're
about to turn Field* API private anyway.
This exposes way too much internal details about the protocol that users
do not need. The specific field getters we provide are sufficient for
any low-level code.

I wrote most of this when I was still very new to Rust and I started
with a very bottoms-up approach. Hence we these API had been public
until now.

I doubt anyone uses these anyway so chances of people's code breaking
are low but even if they do, it's a API breaking release.
@zeenix zeenix marked this pull request as ready for review August 15, 2023 14:38
@zeenix zeenix requested a review from elmarco August 15, 2023 14:39
@zeenix zeenix merged commit d1e10c3 into dbus2:main Aug 16, 2023
7 checks passed
@zeenix zeenix deleted the msg-api-improv branch August 16, 2023 10:52
@zeenix
Copy link
Contributor Author

zeenix commented Aug 16, 2023

For the record, @elmarco ack'ed in a private message. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant