discuss-gnustep
[Top][All Lists]
Advanced

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

Re: objective-c: how slow ?


From: Nicola Pero
Subject: Re: objective-c: how slow ?
Date: Sat, 1 Sep 2001 15:22:33 +0200 (CEST)

Here is a rough thought about how we could implement an inline cache
optimization for the Objective-C runtime, without using self-modifying
code (or better, by using the C equivalent of self-modifying code):

you would modify the compiler so that instead of compiling

 [receiver message];

into 

 {
   IMP __imp = objc_msg_lookup(receiver, @selector(message));
   __imp (receiver, @selector(message));
 }

it would compile it into

 {
   static Class __class = Nil;
   static IMP __imp = NULL;

   if (receiver->isa != __class)
     {
        __class = receiver->isa;
        __imp = objc_msg_lookup(receiver, @selector(message));
     }

   __imp (receiver, @selector(message));
 }

it's a rough sketch, but I suppose something like this might actually
work! :-)

but only if you don't use multithreading.  In multithreading, it is not
actually going to work, unless we add locks, but we can't.  Any idea how
to make it work in multithreading ? 

I suppose we might add it the compiler and it could be turned on with a
certain command line flag.  That flag wouldn't work with threads, so if
you compile with the flag, you mustn't use threads.  Some sort of
`thread-unsafe' optimization.

Btw, notice that a hand-made optimization done directly using IMPs in
Objective-C is faster than an inline cache hit, so in (the extremely rare)
places in which you might need a terrific messaging speed (which,
reasonably speaking, *must* be in a tight loop (and so optimizable by
IMPs) because unless you send some tons of millions of messages, who cares
if it takes 30% more or less time to send a message), you would want to
optimize directly using IMPs anyway. 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]