[Top][All Lists]

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

Re: Objective-C and Smalltalk; speed of message send

From: Richard Frith-Macdonald
Subject: Re: Objective-C and Smalltalk; speed of message send
Date: Thu, 19 Aug 2004 15:38:31 +0100

On 19 Aug 2004, at 15:24, Adrian Robert wrote:

On Aug 18, 2004, at 3:49 PM, Marcel Weiher wrote:

Whoa, an NSDictionary is a pretty heavy-weight item, especially compared to a simple 2D array! Why not stick with the 2D array, if I may ask? After all, one of the point of Objective-C is that it *is* C.

 We decided to use NSStrings as the keys.

Also potentially fairly heavy, though a common choice. I remember people complaining about NSString's performance compared to char* when Foundation was introduced. However, NSString is really for "human readable" text, whereas char* is often more for "tokens", or really just byte-sequences.

To maintain a backwards bridge, we took the old 2D access indices and turned them into a string. And then stored/set them in the NSMutableDictionary via those. The performance was not impressive.

I wouldn't expect it to be. NS(Mutable)Dictionary is pretty slow. One issue is that it copies its keys. Arrrggghh.

Not really a big issue ... if the key is a constant string, a copy is just a retain. If it's not constance, failing to copy would be a significant bug.

While it's good to have the raw C capabilities there for extreme cases, it's NOT much good having a nice, high-level API if it's so slow you end up dropping back to mid-level C (with all of its tedium and error-proneness) much of the time. I'm going to get in trouble here for talking instead of sending code ;), but it seems like the class NSString and at least the plist classes NSDictionary and NSArray ought to be as optimized as well as they can possibly be. These are used everywhere in the libraries and in applications, and effort in this direction should pay off handsomely. I'm sure much has been done already, but perhaps there is still some reasonably low-hanging fruit remaining?

I'm sure there are always possibilities, but I think NSArray and NSDictionary are actually pretty fast. NSString is more of a problem.

I realize there are things that just have to be done for correct behavior (e.g., hash key copying), but I just don't see how any Smalltalk environment should be able to match Objective-C in performance for a straightforward application of strings and dictionaries. We ought to look at these implementations (if any have source available) and see what techniques they are using.

Maybe ... I think that most likely the main problem is using stringWithFormat: That method is slow for a variety of reasons (it's probably faster now than when the smalltalk test was done), not least the fact that it uses the autorelease mechanism. Autorelease is fundamentally pretty slow, and a good garbage collection system would perform better. However, retain/release/autorelease is the way
things are currently done.

reply via email to

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