Re: instance-private-data issue



On Tue, 2003-08-05 at 04:00, Mathieu Lacage wrote:

> > My concern is not beauty, but rather efficiency; looking up a
> > thread-private data key isn't free (*), and
> > g_type_instance_get_private()
> > is intended to be just a few cycles. That already isn't the
> > really the case, which is why we are putting ->priv pointers into new
> > Gtk types, but I'm a little reluctant to make it worse.
> 
> Why did you started to do this ? Is it because it was too slow ? Did you
> have any specific scenario usage which felt really badly slow ? 
> 
> I must say I don't see the point of having private instance pimples in
> GType and not using them in GTK+.

I didn't say we weren't using instance private data in GTK+. I said,
that, where possible (and for types that were already in GTK+-2.2,
it isn't), we are storing a pointer to the instance private
data in the main structure to accelerate lookups.

> > Some timing is probably needed here.
> 
> I'll just repeat what I said: it feels like a very bad idea to trade
> memory at all times for speed at one time. I must say I never expected
> myself that g_type_instance_get_private would be just a few cycles long.
> Is this something you see on your profiles ?

Believing that instance private data *should* be just a few cycles
is a natural consequence of believing that it should be used frequently.
I believe I earlier gave the example of:

 int my_a_get_foo (MyA *a)
 {
   MyAPrivate *priv = MY_A_GET_PRIVATE (a);

   return a->foo;
 }

You really want that to be rougly comparable to speed to the getter
without instance-private-data.

> > The other advantage of the "bloat GTypeInstance" approach is that
> > this may not be the only problem of the form "G_TYPE_FROM_INSTANCE()
> > produces unexpected results in instance_init()". 
> 
> My personal god (namely Darin) would laugh at me if I tried to justify a
> patch with a sentence including the word "may". 

I, or you, can easily construct *artificial* examples of this problem.
I don't think anybody expects the current behavior. I think most
people would be shocked at what result you'd get if you put

 g_print ("Creating a new widget of type %s\n",
g_type_name_from_instance (widget));

into gtk_widget_init(). But I don't know of any real examples where it
is a problem other than than this one, so I said "may".

When considering a couple of courses of action, considering all possible
upsides and downsides is important. Sometimes this upsides and
downsides involve a bug in bugzilla that someone encountered 
last week. Sometimes they involve thinking about bugs that someone
*might* encounter next week. The first get more weight, but 
ignoring the second is silly.

Regards,
						Owen





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