Skip to content

gvarianttype: Garbage Collect GVariantTypeInfo

Christian Hergert requested to merge wip/chergert/gc-varianttypeinfo into main

The goal of this change is to avoid re-parsing GVariantTypeInfo on every creation or parsing of a GVariant byte-buffer. Parsing presents a non-trivial amount of overhead which can typically be elided.

It was discovered that many applications and tooling are re-generating this information upon receiving a D-Bus message as they tend to process messages serially, thus dropping the last reference count.

Previously, when the last reference count for a GVariantTypeInfo was dropped we would finalize the parsed type information.

This change keeps GVariantTypeInfo alive in a Garbage Collected array. The array is collected upon reaching a 32 entries. The number 32 was chosen because it is larger than what I've seen active on various D-Bus based applications-or-daemons.

Take a simple test case of using GVariantBuilder in a loop with a debugoptimized build of GLib. A reduction in wallclock time can be observed in the 35% to more than 70% based on the complexity of the GVariant being created.

For cases like ibus-daemon, it was previously parsing GVariantTypeInfo up to dozens of times per key-press/release cycle.

Closes: #3472 (closed)

Edited by Christian Hergert

Merge request reports