From: Charles Oliver Nutter Date: 2007-12-23T09:35:26+09:00 Subject: Re: Matz says namespaces are too hard to implement - why? Michal Suchanek wrote: > Now I do not say it's useless to add methods to a class w/o the fear > you would stomp on somebody else's added methods. But it only makes > the code look slightly nicer at the cost of some obfuscation of the > origin of the methods and some performance penalty. > Or is the foo also supposed to be visible in methods called from the block? My version just shows changing it within the calls appearing in that block, but I think for it to be generally useful in the typical sense of selector namespaces it would have to affect all downstream calls in the thread as well. > It's dreadfully slow. I tried it when I wanted to add methods to a > Fixnum and found out it does not have a class. Of course, if the > wrapped object is stored somewhere the method does not go away when > do_somethin_with ends. > On the other hand, it is somewhat consistent. If the method overrides > were on the stack you could get different views of the same object > from different places. > > Basically all these things require to store some class and method > indexed hash of overrides somewhere that is searched before the > standard class hierarchy. It requires to do the search multiple times > but is should be like doing the standard lookup 2x or 3x, not the > horrendous slowdown as with the pure ruby delegator. So you're saying the stdlib delegator is slow? Do you have some benchmarks for this? I'd like to examine it and see if I can improve it or speed it up in JRuby. I believe there are parts of Rails that use delegator too (or perhaps only used to), so it would be nice to see if it's a real bottleneck. - Charlie