From: Vidar Hokstad Date: 2008-03-29T23:55:07+09:00 Subject: Re: Why Ruby do not optimize code at all? On Mar 28, 9:06 pm, Daniel Berger wrote: > Hm, couldn't you use method_added behind the scenes somehow? Perhaps > use the opimized parse tree unless method_added is invoked? Or cache > the parse tree? > > Or am I talking nonsense? > Not sure if method_added would be the right solution, but the interpreter can certainly do checks. For the new VM based Ruby implementations for example, it'd be reasonable to do JIT based optimization of it - it'd be relatively easy bookkeeping for the VM implementations to check for the replacement of a specific method of a specific class, and throw away all JIT optimized paths relying on the behavior of that method and revert to the original byte code. That could be done as a quite generic optimization, which pretty much boils down to memoization of the results of frequently occurring subexpressions that are known to be safe to memoize (no side effects / stored state etc.) Vidar