当我将以下文本粘贴到在 ruby-enterprise-2011.03 下运行的 IRB 或 PRY 中时,需要 13 秒。
# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
当在同一台计算机上运行 irb 和其他 ruby 安装时,粘贴并不慢。
jruby-1.5.6
jruby-1.6.3
ruby-1.8.6-p420
ruby-1.8.7-p352
ruby-1.9.1-p431
ruby-1.9.2-p290
ruby-1.9.3-preview1
or Mac OS X's default system install of 1.8.7-p249
这个问题与编辑文本时Rails控制台运行极其缓慢,但我没有使用rvm,并且在写入、编辑或删除文本时没有缓慢的情况;只是粘贴速度慢。 @fl00r 的建议有效,但这不是永久解决方案。
另外,如果粘贴的文本中有硬换行符,则只有最后一行会变慢。例如,粘贴以下文本只需要大约 1.5 秒,
# Lorem ipsum dolor sit amet, consectetur adipisicing elit,
# sed do eiusmod tempor incididunt ut labore et dolore magna
# aliqua.
我注意到 REE 加载了 libreadline 的副本,而其他 ruby 安装都不会加载该副本。有没有办法配置和编译 REE 以忽略 MacPorts 中的 libreadline 文件?
require 'readline'
puts `lsof -p #{$$} | grep -i readline | awk '{print $9}'`
puts
我在几个 ruby 安装上运行了上面的脚本。只有底部的 2 个安装(REE 安装)包含额外的 libreadline。
=== ruby-1.8.6-p36 ======================
/opt/ruby-1.8.6-p36/lib/ruby/1.8/i686-darwin11.2.0/readline.bundle
=== ruby-1.8.6-p420 ======================
/opt/ruby-1.8.6-p420/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle
=== ruby-1.8.7-p352 ======================
/opt/ruby-1.8.7-p352/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle
=== ruby-1.9.1-p431 ======================
/opt/ruby-1.9.1-p431/lib/ruby/1.9.1/i386-darwin11.0.1/readline.bundle
=== ruby-1.9.2-p290 ======================
/opt/ruby-1.9.2-p290/lib/ruby/1.9.1/x86_64-darwin11.0.1/readline.bundle
=== ruby-1.9.3-preview1 ==================
/opt/ruby-1.9.3-preview1/lib/ruby/1.9.1/x86_64-darwin11.0.1/readline.bundle
=== ruby-enterprise-1.8.7-2011.03 ========
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle
/opt/local/lib/libreadline.6.2.dylib
=== ruby-enterprise-1.8.7-2012.01 ========
/opt/ruby-enterprise-1.8.7-2012.01/lib/ruby/1.8/i686-darwin11.2.0/readline.bundle
/opt/local/lib/libreadline.6.2.dylib
When I paste the following text into IRB or PRY running under ruby-enterprise-2011.03, it takes 13 seconds.
# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Pasting isn't slow when running irb with other ruby installations on the same computer.
jruby-1.5.6
jruby-1.6.3
ruby-1.8.6-p420
ruby-1.8.7-p352
ruby-1.9.1-p431
ruby-1.9.2-p290
ruby-1.9.3-preview1
or Mac OS X's default system install of 1.8.7-p249
This question is related to Rails console running incredibly slowly when editing text, but I'm not using rvm, and there is no slowness when writing, editing, or deleting text; Only pasting is slow. @fl00r's suggestion works, but that isn't a permanent fix.
Also, if there are hard newlines in the pasted text, only the last line is slow. For example, pasting the following text only takes about 1.5 seconds
# Lorem ipsum dolor sit amet, consectetur adipisicing elit,
# sed do eiusmod tempor incididunt ut labore et dolore magna
# aliqua.
I've noticed that REE loads a copy of libreadline that none of the other ruby installations load. Is there a way to configure and compile REE to ignore the libreadline file from MacPorts?
require 'readline'
puts `lsof -p #{$} | grep -i readline | awk '{print $9}'`
puts
I ran the above script on several ruby installations. Only the bottom 2 installations (the REE installations) include the extra libreadline.
=== ruby-1.8.6-p36 ======================
/opt/ruby-1.8.6-p36/lib/ruby/1.8/i686-darwin11.2.0/readline.bundle
=== ruby-1.8.6-p420 ======================
/opt/ruby-1.8.6-p420/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle
=== ruby-1.8.7-p352 ======================
/opt/ruby-1.8.7-p352/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle
=== ruby-1.9.1-p431 ======================
/opt/ruby-1.9.1-p431/lib/ruby/1.9.1/i386-darwin11.0.1/readline.bundle
=== ruby-1.9.2-p290 ======================
/opt/ruby-1.9.2-p290/lib/ruby/1.9.1/x86_64-darwin11.0.1/readline.bundle
=== ruby-1.9.3-preview1 ==================
/opt/ruby-1.9.3-preview1/lib/ruby/1.9.1/x86_64-darwin11.0.1/readline.bundle
=== ruby-enterprise-1.8.7-2011.03 ========
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle
/opt/local/lib/libreadline.6.2.dylib
=== ruby-enterprise-1.8.7-2012.01 ========
/opt/ruby-enterprise-1.8.7-2012.01/lib/ruby/1.8/i686-darwin11.2.0/readline.bundle
/opt/local/lib/libreadline.6.2.dylib
发布评论
评论(4)
这是 Readline 和 UTF-8 终端的问题。我没有花时间去追查真正的问题来自哪里,但是,如果您将 $LANG 设置为其他值,问题就会消失。
这不是一个永久的解决方案。
另一个快速解决方法是在粘贴文本后键入附加字符。
如果您重新编译 ruby 不使用 Readline,您也可以返回使用 OSX 的 editline lib。遗憾的是,这也带来了它自己的问题,例如 rubys readline 的 editline 兼容性会阻塞线程。
我还应该指出,不仅仅是 ruby 遇到这个问题,自 Snow Leopard 以来,我在 OSX 上的其他 readline 实现中也看到过这个问题。
This is an issue with Readline and UTF-8 terminals. I have not spent the time to track down where the real issue is coming from, however, if you set $LANG to some other value, the problem will disappear.
This isn't a permanent solution.
Another quick fix is to type an additional character after pasting text.
You could alternatively go back to using OSX' editline lib, if you recompiled ruby to not use Readline. Sadly this comes with it's own problems, such as the editline compatibility for rubys readline blocks threads.
I should also note that it's not just ruby that suffers this issue, I have seen it with other readline implementations on OSX since Snow Leopard.
也许安装纯红宝石readline?
maybe install pure ruby readline?
看起来 REE 的
installer.rb
添加了-I/opt/local/include
和-L/opt/local/lib -Wl,
链接器旗帜。清除这些标志后,REE 编译成功,不包含第二个 readline 库,但由于其他加载错误,生成的 ruby 将不会执行。解决方案是在安装 REE 时暂时删除 MacPorts,这样它就不会链接到额外的 readline 库。
sudo mv /opt/local /opt/localbak
sudo mv /opt/localbak /opt/local
之后,REE安装将与 MacPorts 一起正常工作。
其他解决方案:
编辑:我注意到使用 ruby-build 不会出现此问题
It looks like REE's
installer.rb
adds-I/opt/local/include
and-L/opt/local/lib -Wl,
linker flags. After clearing out those flags, REE compiles successfully without including the 2nd readline library, but the resultant ruby will not execute due to other load errors.A solution is to temporarily remove MacPorts while installing REE so that it doesn't link to the extra readline library.
sudo lsof | grep /opt/local
.sudo mv /opt/local /opt/localbak
sudo mv /opt/localbak /opt/local
After that, the REE installation will work properly alongside MacPorts.
Other solutions:
edit: I've noticed that installing REE with ruby-build doesn't exhibit this problem
尝试添加:
到您的
~/.irbrc
文件,然后重新启动 irb(或运行load '~/.irbrc'
)Try adding:
To your
~/.irbrc
file, and restarting irb (or runningload '~/.irbrc'
)