Skip to content

glib/gvariant: skip bitlock for g_variant_ref_sink()

Christian Hergert requested to merge wip/chergert/g_variant_ref_sink-perf into main

In almost all cases, the variant is sunk shortly after creation and certainly before other threads get a view of it.

This skips the bitlock for STATE_FLOATING, which is also done in g_variant_take_ref(). We can do this because STATE_FLOATING may only be set up-front, never after being cleared.

That allows us to do a relaxed read of the value once (which if it is zero means no additional atomics beyond our ref count increment) as well as a single atomic if we do in fact steal the floating reference.

Without any other GVariant performance changes, this is in the 2% range of benchmarking a tight loop using GVariantBuilder. However, after the rest of them are applied, the percentage is greater due to reduced runtime overhead and lands in the 4.5% range.

Merge request reports

Loading