discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Optimizing Objective-C code


From: Richard Frith-Macdonald
Subject: Re: Optimizing Objective-C code
Date: Sat, 9 Mar 2002 07:25:54 +0000

On Friday, March 8, 2002, at 09:27 PM, Chris B. Vetter wrote:

Hi,

I just stumbled across Mulle Kybernetik, who run a seemingly interesting
series on ways to make ObjC code run faster.

Might be of interest ...

        http://www.mulle-kybernetik.com/artikel/Optimization/


It was ... I had a look at the chapter on 'optimising foundation classes' and was amazed at the performance increase they managed to get replacing NSArray,
and didn't see how that could possibly have been managed.

So I decided to try it under GNUstep. As I was running on an 850 MHz i686 rather than a 450MHz cube, I doubled the number of iterations the test was
doing.

The unoptimised code took 2.7 seconds.
The naive optimisation (avoiding method lookup overheads) reduced that to 1.9 seconds. I couldn't see how the rewritten classes they used to replace NSArray/NSString would
help much, so I decided to try on my 500MHz MacOS-X system -
the code which took 1.9 seconds on my GNU/Linux machine took around 65 seconds there
(averaged over a few runs).

Next, I modified the code to detach a thread before the test ...
ensuring that lots of locking was turned on (all reference count
work has to be lock protected in a multithreaded environment).
This pushed the time under GNUstep up to 6.3 seconds
Under MacOS-X the timing was unchanged ... perhaps MacOS-X performs lno optimisations
for running single threaded?

Finally, I tried varying the number of iterations down to 5 millionm, one million,
and a hundred thousand.
With GNUstep, the timing change was linear ... 6.5 -> 3.2 -> 0.64 -> 0.06
With MacOS-X it was not ... 65 -> 20 -> 3.14 -> 0.24

What does all that tell you?

1. You can't really assume anything about the efficiency of particular methods/classes - you have to try them out. And they can vary radically from implementation to implementation, or release to release, or even depending on the size of the data
being handled!

2. Running multithreaded really slows you down under GNUstep.
An optimisation for really good performance is to avoid using threads or
using any libraries which use threads. Remember, starting a thread at any point will damage the performance of your program and the performance will not be regained when
the thread exits.

3. Enumerating and adding elements to an array is currently very much faster in GNUstep than MacOS-X, even when running threaded... You probably shouldn't bother trying to optimise it.




reply via email to

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