Why are signals considered expensive?

Patrick Doyle wpdster at gmail.com
Mon Nov 3 05:49:26 PST 2014


tl;dr warning -- some of this is for (my) future posterity...

I was just reading the documentation for the appsink API
(http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-appsink.html)
and read in the section for gst_app_sink_set_emit_signals() that "This
option is by default disabled because signal emission is expensive and
unneeded when the application prefers to operate in pull mode."

A little further down the page, I read the description of the
gst_app_sink_set_callbacks() function which claims to be "an
alternative to using the signals, it has lower overhead and is thus
less expensive, but also less flexible."

After reading those two sections, I realized that "signal" must mean
something more complicated than "callback" (which was how I was
interpreting the word).  According to the Gstreamer documentation
about signals (http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/chapter-building-signals.html),
"GObject signals can be used to notify applications of events specific
to this object. Note, however, that the application needs to be aware
of signals and their meaning, so if you're looking for a generic way
for application-element interaction, signals are probably not what
you're looking for. In many cases, however, signals can be very
useful. See the GObject documentation for all internals about
signals."

OK, so I head on over to the GObject documentation about signals
(https://developer.gnome.org/gobject/stable/signal.html), and learn
that "every user event (keystroke or mouse move) is received from the
X server and generates a GTK+ event under the form of a signal
emission on a given object instance", which sounds a lot like signals
should be pretty lightweight.  But then I continue reading about
signal registration, and the 10 different parameters required
(including scary things like GClosures and GSignalMarshallers and
such) and I begin to wonder if that is what is meant by signals being
considered expensive.

So, I think I'll ask my question anyway (and start a separate thread
for a different, related question).  Why are signals considered
expensive?

--wpd


More information about the gstreamer-devel mailing list