dbus2 / zbus

Rust D-Bus crate.
Other
360 stars 82 forks source link

Remove/reduce `format!` use in `Interface::introspect_to_writer` impl in `interface` #828

Open zeenix opened 4 months ago

zeenix commented 4 months ago

This is adding to the binary size (#304).

The problem is number of format! calls and format macro generating a lot of code. Possible solutions:

HookedBehemoth commented 2 months ago

Could you elaborate on the issue with doing this at compile time some more? If it's all done then, indentation can be inferred there. And in my eyes, the signatures could also be obtained unless they are inferred.

zeenix commented 2 months ago

Could you elaborate on the issue with doing this at compile time some more? If it's all done then, indentation can be inferred there.

You're right that the level argument of Interface::introspect_to_writer can be changed to a const generic and we can do so w/o bumping the major version since Interface is declared to be unstable API.

However, the indent argument is bumped internally for each level here. Perhaps, the inner indentation level should be something the Interface implementation (i-e the macro) should handle and caller of introspect_to_writer should just pass the main indentation level. :thinking:

And in my eyes, the signatures could also be obtained unless they are inferred.

I only wish it was that easy. :cry: Currently in rust you can't concatenate strings at compile time unless they're themselves literals (trait constants can't work). I do have a plan now to make most signature handling (especially during ser/de) constant though, through parsed signatures (#882). I'm planning on working on this during the weekend/next week.