Type checking



In a previous thread about sealing accessors and how that means more
type checking,

On Wed, 2010-03-17 at 17:10 +0000, Emmanuele Bassi wrote: 
> this might be the kick in the arse needed to get type checking down to a
> minimal cost

We have observed in the past that the type checking calls are 2-3% of
program run time [that needs to be verified with the current stack, of
course, but we've seen reports like that on the GTK lists within the
last few years]. That's a lot :|

I've often wondered about it, because on the one hand we have 

        void
        gtk_button_set_label (GtkButton   *button,
        		      const gchar *label)
        {
          g_return_if_fail (GTK_IS_BUTTON (button));
        
in gtk/gtkbutton.c which after wading through several macros ends up as
a call to g_type_check_instance() in glib/gtype.c with some if/else
blocks around it.

Meanwhile most of the time (in C anyway) people call 

        gtk_button_set_label(GTK_BUTTON(button), "Hello World");

which ends up as a call to g_type_check_instance_cast() which does most
of the same stuff as g_type_check_instance() does.

I'm aware of this partly because in java-gnome's generated code we ended
up casting to the public types directly (wasn't my idea, it's what I
inherited, and lo it works):

        GtkButton* button;
        ...
        button = (GtkButton*) user_data;
        gtk_button_set_label(button, "Hello World");

and it's been working for us because a) we have correct type information
so we're casting the right thing anyway, and b) because the first thing
the functions we are calling do is check the type of the inbound
pointer.

So I'm wondering: can we [C, GTK] do away with one of the code paths
entirely? It'd be nice to do away with the checks in the internal
accessors, of course, but that isn't going to happen because the
internal code is now using the public accessors.

So maybe we can at least not check in the cast macros?

Again, I haven't profiled a C only applcation in a while, so this may be
out of date. Someone with a GUI heavy C app would need to check. But
this used to be really expensive for C apps. And meanwhile we're using
GTK for some years now without using the cast macros at all, and things
are working. So that's at least a datapoint.

AfC
Sydney


-- 
Andrew Frederick Cowie

Operational Dynamics is an operations and engineering consultancy
focusing on IT strategy, organizational architecture, systems
review, and effective procedures for change management: enabling
successful deployment of mission critical information technology in
enterprises, worldwide.

http://www.operationaldynamics.com/

Sydney   New York   Toronto   London

Attachment: signature.asc
Description: This is a digitally signed message part



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