On Mon, Sep 30, 2002 at 10:02:36PM +0900, Bulat Ziganshin wrote:
> Hello Yukihiro,
> 
> Monday, September 30, 2002, 1:56:25 PM, you wrote:
> 
> YM> No.  Tree search result is stored in the cache, whose hit rate is more
> YM> than 95%.  It means hash seach traversing inheritance tree happens 1
> YM> to 20.  If Ruby is slow (and in fact it is), I think there's other
> YM> bottlenecks than method dispatching.

Do you have any idea about where they might be?

> YM> |consider two examples i stated above. in C and in Ruby. so...?
> 
> YM> I was talking about Ruby's bottleneck, no comparison against other
> YM> compiled languages.
> 
> well. consider "2+2" example. when we compile ruby to c, we need to
> dispatch to Fixnum.+ method. if we exactly know what Fixnum.+ body is:
> 
> Fixnum +(Fixnum b)
>   return integer_add( self.representation, b.representation)
> end
> 
> then we can compile "2+2" to just one c/asm instruction. if we don't
Only if there's no dynamic dispatching or you're positive that Fixnum#+
won't be redefined, or you can freeze classes. Otherwise you have to
specify which methods are "virtual" (as in C++).

But it remains true that if everything's statically defined you can even
optimize method calls away and inline them :)

> know, we have to call rb_funcall with all those overhead. so, if i'm
> right, strong typing is the first and most important step to fast
> compiled code. i say nothing about interpreter, it is topic for another
> discussion

Even w/ dynamic typing, method dispatching can be made quite fast: look
at Psyco, the specializing Python compiler. Not as relevant to AST tree
walks as to bytecode interpretation, though.

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
  
Q: What's the big deal about rm, I have been deleting stuff for years?  And 
   never lost anything.. oops!
A: ...
	-- From the Frequently Unasked Questions