Re: Overhead of type casting when using GObject system

Hi Emanuele,

thanks for the comprehensive response.
On 10/02/13 12:08, Emmanuele Bassi wrote:
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
So do I understand if correctly that the cast checks can be disabled invididually per compiled object file, e.g. before linking them together? An all I have to do is adding these lines:

#include <glib/gobject.h>

in my source file?

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
- 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.
Great, good to know.


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