什么让Ruby慢? [英] What makes Ruby slow?

查看:111
本文介绍了什么让Ruby慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby在某些事情上很慢。但是它的哪些部分是最有问题的?

垃圾收集器对性能有多大影响?我知道有些时候我独自运行垃圾回收器需要几秒钟的时间,尤其是在使用OpenGL库时。



我已经使用了带有Ruby的矩阵数学库,特别慢。 ruby如何实现基本的数学运算有问题吗?



Ruby中有没有动态功能可以高效实现?如果是这样,Lua和Python等其他语言如何解决这些问题?



最近的工作是否显着提高了性能?

解决方案


Ruby很慢。但是它的哪些部分是最有问题的?

它为方法提供了后期查找功能,以提高灵活性。这会降低它的速度。它还必须记住每个上下文的变量名以允许eval,所以它的框架和方法调用较慢。此外,它目前还没有一个好的JIT编译器,尽管MRI 1.9有一个字节码编译器(这更好),jruby将它编译为java字节码,然后通过HotSpot JVM的JIT编译器编译它,但它最终只是关于速度与1.9相同。


垃圾收集器的效果表现如何?我知道我有些时候独自运行垃圾回收器需要几秒钟的时间,尤其是使用OpenGL库时。


http://www.igvita.com / 2009/06/13 / profiling-ruby-with-googles-perftools / 我会说大概需要10%这是相当多的 - 你可以通过增加gc.c中的malloc_limit来减少命中并重新编译。


我使用的矩阵数学库特别慢。


Ruby 1.8没有实现它实现的基本数学运算Numeric classes and you '每次打电话给Fixnum#+ Fixnum#/ /打电话一次 - 这很慢。 Ruby 1.9通过内联一些基本的数学运算来作弊。


有没有Ruby中的动态特性无法高效实现?如果是这样,Lua和Python等其他语言如何解决这些问题?


像eval这样的东西很难高效地实现,尽管很多工作可以做,我敢肯定。 Ruby的踢球者是它必须适应另一个线程中的某个人 改变一个类的定义,所以它必须非常保守。


最近有哪些工作显着改善了性能?



<1.9>就像是2x加速。它也更节省空间。 JRuby一直在努力提高速度[而且可能比KRI花费的时间更少]。除此之外,除了我一直在研究的小爱好事物之外,我还没有意识到。还要注意,由于编码的友好性,1.9的字符串有时会变慢。


Ruby is slow at certain things. But what parts of it are the most problematic?

How much does the garbage collector affect performance? I know I've had times when running the garbage collector alone took several seconds, especially when working with OpenGL libraries.

I've used matrix math libraries with Ruby that were particularly slow. Is there an issue with how ruby implements basic math?

Are there any dynamic features in Ruby that simply cannot be implemented efficiently? If so, how do other languages like Lua and Python solve these problems?

Has there been recent work that has significantly improved performance?

解决方案

Ruby is slow. But what parts of it are the most problematic?

It does "late lookup" for methods, to allow for flexibility. This slows it down quite a bit. It also has to remember variable names per context to allow for eval, so its frames and method calls are slower. Also it lacks a good JIT compiler currently, though MRI 1.9 has a bytecode compiler (which is better), and jruby compiles it down to java bytecode, which then (can) compile via the HotSpot JVM's JIT compiler, but it ends up being about the same speed as 1.9.

How much does the garbage collector effect performance? I know I've had times when running the garbage collector alone took several seconds, especially when working with OpenGL libraries.

from some of the graphs at http://www.igvita.com/2009/06/13/profiling-ruby-with-googles-perftools/ I'd say it takes about 10% which is quite a bit--you can decrease that hit by increasing the malloc_limit in gc.c and recompiling.

I've used matrix math libraries with Ruby that were particularly slow. Is there an issue with how ruby implements basic math?

Ruby 1.8 "didn't" implement basic math it implemented Numeric classes and you'd call things like Fixnum#+ Fixnum#/ once per call--which was slow. Ruby 1.9 cheats a bit by inlining some of the basic math ops.

Are there any dynamic features in Ruby that simply cannot be implemented efficiently? If so, how do other languages like Lua and Python solve these problems?

Things like eval are hard to implement efficiently, though much work can be done, I'm sure. The kicker for Ruby is that it has to accomodate for somebody in another thread changing the definition of a class spontaneously, so it has to be very conservative.

Has there been recent work that has significantly improved performance?

1.9 is like a 2x speedup. It's also more space efficient. JRuby is constantly trying to improve speed-wise [and probably spends less time in the GC than KRI]. Besides that I'm not aware of much except little hobby things I've been working on. Note also that 1.9's strings are at times slower because of encoding friendliness.

这篇关于什么让Ruby慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆