discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Switching to libobjc2


From: David Chisnall
Subject: Re: Switching to libobjc2
Date: Mon, 2 Jul 2012 17:13:01 +0100

On 2 Jul 2012, at 16:41, Konstantin Osipov wrote:

> * David Chisnall <theraven@sucs.org> [12/06/28 12:48]:
>> As the author of the GNUstep runtime, I think that's great. On
>> x86[-64] and ARM it now implements the objc_msgSend() dispatch
>> mechanism.  This is enabled by default if you compile with clang
>> on *BSD, and optionally on Linux.  When using this mechanism,
>> message sending is very fast.  When using the traditional
>> two-stage lookup, it's slightly slower than the GCC runtime
>> because it also supports a few other cases (specifically, small
>> objects hidden inside pointers) which the GCC runtime does not
>> support.
> 
> Is it TYPE_DEPENDANT_DISPATCH? I checked and we are compiling
> with it turned on.

No, it's a compiler option for the Objective-C code that you compile: 
-fno-objc-legacy-dispatch.

>> You may want to make use of this support in your code.
> 
> How do I use a slow object slot for my own objects? 

You need to register the class with objc_registerSmallObjectClass_np().  On 
32-bit platforms you can register 1 class, on 64-bit platforms you can register 
7.  Note that the object must fit inside a pointer to use this.

> In particular we have a central object in the system, called
> Request, which is created and dispatched for every user request.
> 
> Simply going away from Objective C dispatch to a C function call
> for this object gives 16% overall performance boost. 

Then it sounds like that's the correct thing to do.  You don't have to use late 
binding for everything in Objective-C, that's the point of using Objective-C 
instead of Smalltalk.

> We have now tried the libobjc2 runtime, and discovered that it is
> even slower in our case than the GCC runtime (a drop from average
> of 350k rps to 330k rps, TYPE_DEPENDENT_DISPATCH is on).
> 
> There is a slight chance that we're not compiling it correctly
> though.

If you're not specifying -fno-objc-legacy-dispatch then you will be using the 
two-stage lookup, so this is expected.  

>> There are also some LLVM optimisations shipped with the runtime
>> that can do things like cache method lookups in loops, which can
>> make the cost of message sending even cheaper.
>> 
>> If you want to catch C++ exceptions, then you have two choices.
>> The simplest is to compile your code as Objective-C++.  This
>> will then use the Objective-C++ personality function and
>> everything should work by magic.  Alternatively, you must
>> provide and register a class that is used to pass C++ exceptions
>> to Objective-C handlers.  This is required because the GCC ABI
>> did not provide a callback into the runtime for disposing of
>> exceptions.  The CXXException class in GNUstep does this (you
>> can also explicitly catch this class if you want to catch C++
>> exceptions from Objective-C code).
> 
> Is there anywhere an example for how to box a C++ exception,
> if not using GNUSTEP or Foundation framework?

Look at the CXXException class in GNUstep, it implements everything you need.

David

-- Send from my Jacquard Loom




reply via email to

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