From: Clifford Heath Date: 2011-04-30T16:45:24+09:00 Subject: Re: Hash Surprises with Fixnum, #hash, and #eql? On 04/27/11 15:23, Charles Oliver Nutter wrote: > On Wed, Apr 20, 2011 at 9:53 PM, Clifford Heath wrote: >> I'm not. I'm expecting that JRuby would detect that a core Fixnum >> method has been monkey-patched, and set a global variable. >> ... > Well, it has to get the value from somewhere. ... it's two field > dereferences and one (inlined) virtual method invocation Ouch. No wonder it hurts. I hadn't looked into the internals of JRuby, but I assumed that you had some native C (JNI or whatever) in there, which could make this feasible. I can totally understand you not wanting any native extensions though! It seems that a collection of such flags at known offsets inside a singleton instance could make this a lot quicker. There's a finite need for such things, so it's not as though it would pervade all of the interpreter. Your argument (from a previous response) that cross-thread effects of monkey-patching was "somewhat undefined" was my thinking also, but contrary to John's accusation, thought it could be (mostly?) hidden under the existing synchronisation around method definition. > In general we have followed the path of matching MRI in such cases, > except when there's a very strong argument not to do so. If you can > convince Ruby core, or if you think you have a strong enough case for > deviating from MRI's behavior, go ahead and file the bug and we can > continue exploring it there. I think the argument that "folk don't do it, therefore they wouldn't" isn't a strong one. Look for example at Rail's HashWithIndifferentAccess, which makes string and symbol keys interchangeable. I merely want to do the same thing with Fixnums and Floats. If you can't make it quicker (than you outlined), best to drop it I guess. I've mostly worked around the need for my current library. Clifford Heath.