views:

92

answers:

2

Those outside of the ruby community (and some inside) oft reference ruby applications as being slow. For many of us this is an irrelevance, IO bound operations etc. However, when it does become a problem there is little to hold us back from taking advantage of native code to speed things up. To this end I am wondering why RoR (itself the target of many 'slow' comments) doesn't make use of any native elements to speed itself up?

Is there a particular reason? Is there a lack of tight loops to optimise within the codebase?

+9  A: 

Rails takes advantage of "native", aka compiled, extensions, but it keeps them as separate and optional libraries. For instance, Rails lets you use nokogiri as an XML parser, instead of the standard Ruby-based parser.

There are at least 3 reasons why Rails probably won't replace internal functions with C/C++ equivalents.

  • Rails is a Ruby framework. Because it's a Ruby framework, you can expect contributors to know about Ruby, but by using C libraries you force the entire Ruby ecosystem to also be C programmers. And this would probably mean a smaller number of contributors to the framework itself.
  • If you ever tried to install on Windows a Gem which includes C extensions, then you probably already know why it's a bad idea to use C code within Rails.
  • Rails happily runs on standard Ruby and the most part of alternative Ruby distributions, such as JRuby. Using C code in Ruby, would require to provide Java/Python/... counterparts of the same code. In fact, Gems with embedded C extensions currently are not compatible with JRuby.
Simone Carletti
To which add, "To make the RoR framework faster would be to optimize the one component that is *not* the critical constraint in most RoR applications."
Wayne Conrad
I thought as much, i mealy wondered if it was a symptom of being compatible or a politically selected ideology of remaining ruby through and through. Much appreciate the incite though!
roja
A: 

it does use them, if you install them as gems (the mysql gem, memcache gem, RedCloth, etc.)

In general, though, it relies on the VM to optimize the code. Otherwise it would be hard for it to work on all the platforms ruby does.

rogerdpack