-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Make zvariant::Signature
completely static & turn Type::signature
to trait const
#882
Comments
After a lot of different approaches, I finally came to a solution that works and I'm happy with: https://github.com/zeenix/experiments/blob/a6b790a4619eacd5885111c8f4bbe371f36cec62/static-dbus-signature/src/signature.rs It's a nice compromise where Type impls (which is most of the cases) always have a completely const signature but anything needing dynamic signature needs to allocate. Perhaps it would be best to use I'll need to check signature use/needs in the code base to see if this will work for zbus needs but I'm feeling confident. |
Quoting from #966
Actually, I realized that this isn't true. The only reason This makes it important to do this already before the next 3.0 release. Here is the rough TODO:
|
oh actually, no. 😆 The other reason is that adding a const w/o a default value to public trait ( |
named `SIGNATURE`. We also remove `Type::signature` method, since `parsed::Signature` can be easily converted to a `crate::Signature`. This commit makes similar changes to `DynamicType` and `DynamicDeserialize` as well. This is an API break that breaks all code that implements `Type` (manually), `DynamicType` and/or `DynamicDeserialize`. In return, we eliminate a lot of allocations, which can make a big difference when it comes to (de)serialization on low-end machines. Fixes dbus2#882.
Convert `Type::parsed_signature` to a const, named `SIGNATURE`. We also remove `Type::signature` method, since `parsed::Signature` can be easily converted to a `crate::Signature`. This commit makes similar changes to `DynamicType` and `DynamicDeserialize` as well. This is an API break that breaks all code that implements `Type` (manually), `DynamicType` and/or `DynamicDeserialize`. In return, we eliminate a lot of allocations, which can make a big difference when it comes to (de)serialization on low-end machines. Fixes dbus2#882.
Convert `Type::parsed_signature` to a const, named `SIGNATURE`. We also remove `Type::signature` method, since `parsed::Signature` can be easily converted to a `crate::Signature`. This commit makes similar changes to `DynamicType` and `DynamicDeserialize` as well. This is an API break that breaks all code that implements `Type` (manually), `DynamicType` and/or `DynamicDeserialize`. In return, we eliminate a lot of allocations, which can make a big difference when it comes to (de)serialization on low-end machines. Fixes dbus2#882.
When I wrote zvariant, I was still very new to Rust and didn't make the best choices in some regard. Recently I looked into the
postcard-rpc
code, and that project also seem to have something very similar to a signature: a Schema. However, unlike ourSignature
type,Schema
is completely static and allocation free (it's targeted for microcontrollers). So it got me thinking, if ourSignature
was similar, we could not only avoid a lot of allocations, but greatly optimize the ser/de process (according to the last benchmarks I conducted, signature parsing is what costs us the most, especially for array types). So something like this:All the above code works. 🍒 on top if we can make this work too:
but I suspect it's not possible and one part that will require allocation. However, with
Display
implementation, we can support writing to fixed sized buffers too.Another possible hurdle could be
zvariant::DynamicType
. Maybe there could also be aDynamicSignature
and/orSignature
could have lifetime. Something I need to figure out..Of course, this all would mean breaking API.
The text was updated successfully, but these errors were encountered: