Re: Overhead of type casting when using GObject system



On 9 February 2013 12:43, Lanoxx <lanoxx gmx net> wrote:
>> However those cast checks can be disabled at compile time removing the
>> overhead, so GTK_WIDGET(foo) would be equivalent to (GtkWidget *) foo.
>
> Ah thats good to know. But still I believe that most applications that are
> shipped with gnome are not compiled that way.

stable releases of gtk automatically disable cast checks for internal
usage; it's actually pretty easy to do, you just need to define
G_DISABLE_CAST_CHECKS symbol before including glib-object.h.

disabling cast checks is usually the result of performance profiling,
tho, so it should only be used if you have profiled your application
code and verified that type casting is high on the profiles; there are
also various ways to avoid that, by using ancillary values and the
correct type to minimize casting, before a blanket type cast check
disable.

> So what overhead does that
> actually create.

on a typical laptop, you can do various milions of type checks per
second; there is a type check performance test in the GObject test
suite: http://git.gnome.org/browse/glib/tree/tests/gobject/performance.c
- you can compile glib and the performance test yourself, and do a
quick check on the expected upper bound of the numbers of type checks.

in my professional experience, you'll have many issues before the type
checks will raise to a relevant portion of the performance profile.
once you get there, you can clean up and reorganize your code before
deciding whether or not to build your stack and your application
without type checks.

ciao,
 Emmanuele.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]