From: Chad Perrin Date: 2006-07-27T07:41:10+09:00 Subject: Re: For performance, write it in C On Thu, Jul 27, 2006 at 06:33:08AM +0900, Ashley Moran wrote: > > Just out of curiosity (since I don't know much about this subject), > what do yo think of the approach Microsoft took with the CLR? From > what I read it's very similar to the JVM except it compiles directly > to native code, and makes linking to native libraries easier. I > assume this is closer to JVM behaviour than Perl 5 behaviour. Is > there anything to be learnt from it for Ruby? I'm not as familiar with what's going on under the hood of the CLR as the JVM, but from what I do know it exhibits both advantages and disadvantages in comparison with the Java VM. Thus far, the evidence seems to be leaning in the direction of the CLR's advantages over the JVM coming into play more often than the disadvantages, however, which seems to indicate that the compromises that were made may have been the "right" compromises, as far as this comparison goes. In fact, the CLR seems in some ways to be a compromise between Perl-style JIT compilation and Java-style bytecode compilation with runtime VM-interpretation (there really needs to be a term for what a VM does separate from either compilation or interpretation, since what it does generally isn't strictly either of them). There may well be something to learn from that for future Ruby implementations, though I'd warn away from trying to take the "all languages compile to the same intermediate bytecode" approach that the CLR takes -- it tries to be too many things at once, basically, and ends up introducing some inefficiencies in that sense. If you want to do everything CLR does, with Ruby, then port Ruby to the CLR, but if you want to simply gain performance benefits from studying up on the CLR, make sure you cherry-pick the bits that are relevant to the task at hand. I think Ruby would probably best benefit from something somewhere between the Perl compiler's behavior and the CLR compiler. Specifically, compile all the static algorithm behavior in your code to something persistent, link in all the rest as uncompiled (though perhaps parse-tree compiled, which is almost but not quite the same as bytecode compiled) code, and let that be machine-code compiled at runtime. This might even conceivably be broken into two separate compilers to minimize the last-stage compiler size needed on client systems and to optimize each part to operate as quickly as possible. Run all this stuff past a true expert before charging off to implement it, of course. I'm an armchair theorist. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "It's just incredible that a trillion-synapse computer could actually spend Saturday afternoon watching a football game." - Marvin Minsky