Why GVariant? (Re: Starting the kdbus discussions
Lennart Poettering
mzqohf at 0pointer.de
Thu Jan 2 07:37:41 PST 2014
On Thu, 02.01.14 16:16, rony (rony at wu.ac.at) wrote:
> > a bit cleaner (since in gvariant the serialization of a
> > specific data object is always the same regardless what comes before it,
> > which is not the case for dbus1 marshalling), and more efficient (as you
> > can seek to any element in an array or struct freely in O(1) time, even
> > if the elements have a variable length, which was O(n) before with n
> > being the number of elements).
>
> Well that may be the case in theory, but how about real world
> programs? How about timing comparisons for real-world use cases dbus
> vs. gvariant (real world usages, edge cases)?
I think you are overestimating the difference between the two
marshallings. Actually, for the simpler types marshalling in GVariant
and dbus1 is even identical, only for the complex type it differs. And
the difference is mostly just about framing and alignment, and neither
are particularly hard to calculate, they are just slightly
different. The benefit you get when reading them though, since in
gvariant random access into complex data structs like arrays or structs
is always O(1), and dbus1 loses out there by being O(n).
> > GVariant has been part of GLib since a long time, and is used as storage
> > format of dconf among other things. Using GVariant as transport
> > marshalling hence makes usecases like this (i.e. where you frequently
> > use the same data on disk and on IPC) particularly efficient.
> What about systems that do not have GLib?
>
> Implementing GVariant is possible of course, but seems to be more complex (and hence more
> error-prone) than dbus de/serialisation.
It's not really more complex. You could even argue it's easier, since
everything is nicely decomposable in gvariant, while it isn't in
dbus1. In gvariant marshalling you can hence just treat each type
seperately and independently of what is stored within it, and implement
it, while in dbus1 you kinda have to throw everything into the same mix
right from the beginning, if you follow what i mean.
In our own libsystem-bus bus library the marshaller for dbus1 and
gvariant actually follows mostly the same codepaths for the overall
structure, just the framing and alignment is done in
marshalling-specific code blocks.
> > For security reasons it is always a good idea to enforce certain things
> > on the data you transfer, like compatibility with C strings or UTF-8
> > validity.
> Are you sure? AFAIK dbus allows the transport of UTF-8 encoded
> strings, which AFAIK may contain nul byte characters.
Yes I am sure.
Lennart
--
Lennart Poettering, Red Hat
More information about the dbus
mailing list