3 ms·
Ruby might just need a better implementation with more time spent on optimization. http://maglev.gemstone.com/ http://maglev.gemstone.com/ is going in this dir
by mbrubeck 17y ago
Ruby might just need a better implementation with more time spent on optimization. http://maglev.gemstone.com/ http://maglev.gemstone.com/ is going in this direction.
But also, Lua was always designed with cleanness and simplicity of implementation in mind. Its developers have strong backgrounds in both theory and engineering, which you can see in their interview in the book Masterminds of Programming. They've been very conservative about the design of the language. In contrast, Ruby feels much messier and more "evolved" - look at its Yacc grammar[1], for example, compared to the grammar of JavaScript or Lua[2]. Even the Ruby lexer is full of weird edge cases. Much of MRI is like that, and for years it was the only "spec" for the language; now its decisions have been reverse-engineered and inherited by all other implementations.
[1]: http://blog.nicksieger.com/articles/2006/10/27/visualization-of-rubys-grammar http://blog.nicksieger.com/articles/2006/10/27/visualization...
[2]: http://www.lua.org/manual/5.1/manual.html#8 http://www.lua.org/manual/5.1/manual.html#8
[By the way, I've used Ruby for years and like it at lot, while I've written only a few lines of Lua code and like it but am not deeply familiar with it.]
- dchest 17y agoAlso, "The Evolution of Lua" — an interesting paper that shows how they came to this fast and somewhat elegant language: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.3859&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.... [PDF]
- silentbicycle 17y agoAlso good: "The Implementation of Lua 5.0" (http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/sblp2005.pdf http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/sblp2005.pdf). Past discussion: http://news.ycombinator.com/item?id=617278 http://news.ycombinator.com/item?id=617278 If you want to learn Lua, Ierusalimschy's _Programming in Lua_ (http://www.inf.puc-rio.br/~roberto/pil2/ http://www.inf.puc-rio.br/~roberto/pil2/) is by far the best book. Lua is one of my favorite languages. While it's good on its own, you'll get a lot more out of it if you're comfortable with C. Lua+C is an excellent combination.
- ambulatorybird 17y agoJust chiming in as another Lua fan; I really like it because it's like the Scheme of imperative scripting languages. And while we're passing around links to papers, I've found the following the be good for additional insight: Lua Performance Tips: (http://www.lua.org/gems/sample.pdf http://www.lua.org/gems/sample.pdf) A No-Frills Introduction to Lua 5.1 VM Instructions: (http://luaforge.net/docman/view.php/83/98/ANoFrillsIntroToLua51VMInstructions.pdf http://luaforge.net/docman/view.php/83/98/ANoFrillsIntroToLu...)
- yread 17y agoAgree. If you want to learn more about Lua+C check out sources of this awesome game: http://springrts.com/ http://springrts.com/
- derefr 17y agoIt'd be interesting to see how fast Ruby would run "cached" (i.e. with the AST already assembled in memory,) to see how much of the time is really spent in the parsing and lexing phases.
- mbrubeck 17y agoNote that I'm not claiming Ruby's parser and lexer are slow, or that they're the cause of any greater problems. I'm just picking on them as one example of deeper differences between the Ruby and Lua designs/implementations.
- haberman 17y agoAlso, Ruby has much more complicated rules for method dispatch. Lua just has functions, and if you want to implement any more complicated dispatch, you have to do it yourself. Once I implemented Ruby-like dispatch on top of Lua, and it was terribly slow: http://blog.reverberate.org/2009/02/09/disappointment/ http://blog.reverberate.org/2009/02/09/disappointment/ To make a long story short, porting my existing Lua project to use my Ruby-like method dispatch resulted in a 4x slowdown.
- stcredzero 17y agoRuby might just need a better implementation with more time spent on optimization...But also, Lua was always designed with cleanness and simplicity of implementation in mind Ease of implementation has a multiplier effect with Open development effort. Not only do you get more of "more eyeballs," new contributors can ramp up faster. There tends to be a better effort/ fun ratio. Even the Ruby lexer is full of weird edge cases. Actually, the lexer sets state that changes the operation of the parser and vice versa.