问题
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
回答1:
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.
回答2:
maybe install pure ruby readline?
回答3:
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.
- Quit all processes that are accessing MacPorts files. You can see which ones are running with
sudo lsof | grep /opt/local
. sudo mv /opt/local /opt/localbak
- Open a new terminal, then compile and install REE
sudo mv /opt/localbak /opt/local
After that, the REE installation will work properly alongside MacPorts.
Other solutions:
- Uninstall MacPorts permanently, and install REE as usual
- Use MRI or another version of Ruby instead of REE
edit: I've noticed that installing REE with ruby-build doesn't exhibit this problem
来源:https://stackoverflow.com/questions/7296169/pasting-text-into-irb-is-incredibly-slow-readline-issue