Why Strings as Classes?

Benji Smith dlanguage at benjismith.net
Tue Aug 26 10:25:40 PDT 2008


Walter Bright wrote:
> Yigal Chripun wrote:
>> a) people here said that a virtual call will make it slow. How much
>> slow? how much of an overhead is it on modern hardware considering also
>> that this is a place where hardware manufacturers spend time on
>> optimizations?
> 
> Virtual function calls have been a problem for hardware optimization. 
> Direct function calls can be speculatively executed, but not virtual 
> ones, because the hardware cannot predict where it will go. This means 
> virtual calls can be much slower than direct function calls.

What about for software optimization?

I seem to remember reading something about the Objective-C compiler 
maybe six or eight months ago talking about some of its optimization 
techniques.

Obj-C uses a message-passing idiom, and all messages use dynamic 
dispatch, since the list of messages an object can receive is not fixed 
at compile-time.

If I remember correctly, this article said that the dynamic dispatch 
expense only had to be incurred once, upon the first invocation of each 
message type. After that, the address of the appropriate function was 
re-written in memory, so that it pointed directly to the correct code. 
No more dynamic dispatch. Although the message handlers aren't resolved 
until runtime, once invoked, they'll always use the same target.

Or some thing like that.

It was an interesting read. I'll see if I can find it.

--benji



More information about the Digitalmars-d mailing list