From: Ron M Date: 2005-08-18T03:29:53+09:00 Subject: Re: Prototype-based / Ruby question Eric Mahurin wrote: > > The biggest problem I have with being able to add/remove/modify > methods of an object (using a meta class or directly in the > object's class) is the future of optimization in Ruby. Adding > methods may not cause too much of an issue, but modifying them > sure could. For example: > > i = 0 > i += 1 > > In this case, Ruby could recognize that i is always a Fixnum > (or a Bignum depending on how smart it is). If it knew exactly > what "+" was for a Fixnum, it would be able to in-line that C > call (in this hypothetical Ruby compiler). Unfortunately, "+" > could be anything since it can change at run-time. Seems like the same issue Java and Self compilers have when new classes are loaded. There are Java compilers that optimize method calls by inlining them, and then "dynamically deoptimize" those if a derived class that changes the meaning of that inlined code is loaded. Here's one paper on such dynamic de-optimization: http://research.sun.com/self/papers/dynamic-deoptimization.html Isn't the real challenge your hypothetical "could recognize that i is always a Fixnum" condition. If the ruby compiler could do this, couldn't that same logic recognise that it is always a pristine, unmodified Fixnum. Knowing the type sounds to me like the hard part of the problem. IIRC Lisp added optional type declarations to the language that you can use inside performance critical areas like tight-loops.