将文本粘贴到 IRB 中的速度非常慢。读线问题?

发布于 2024-12-02 20:01:38 字数 2224 浏览 2 评论 0 原文

当我将以下文本粘贴到在 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

静若繁花 2024-12-09 20:01:38

这是 Readline 和 UTF-8 终端的问题。我没有花时间去追查真正的问题来自哪里,但是,如果您将 $LANG 设置为其他值,问题就会消失。

这不是一个永久的解决方案。

另一个快速解决方法是在粘贴文本后键入附加字符。

如果您重新编译 ruby​​ 不使用 Readline,您也可以返回使用 OSX 的 editline lib。遗憾的是,这也带来了它自己的问题,例如 ruby​​s 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.

心如荒岛 2024-12-09 20:01:38

也许安装纯红宝石readline?

maybe install pure ruby readline?

墟烟 2024-12-09 20:01:38

看起来 REE 的 installer.rb 添加了 -I/opt/local/include-L/opt/local/lib -Wl, 链接器旗帜。清除这些标志后,REE 编译成功,不包含第二个 readline 库,但由于其他加载错误,生成的 ruby​​ 将不会执行。

解决方案是在安装 REE 时暂时删除 MacPorts,这样它就不会链接到额外的 readline 库。

  1. 退出所有正在访问 MacPorts 文件的进程。您可以使用 sudo lsof | 查看哪些正在运行。 grep /opt/local.
  2. sudo mv /opt/local /opt/localbak
  3. 打开一个新终端,然后编译并安装REE
  4. sudo mv /opt/localbak /opt/local

之后,REE安装将与 MacPorts 一起正常工作。

其他解决方案:

  • 永久卸载 MacPorts,然后像往常一样安装 REE
  • 使用 MRI 或其他版本的 Ruby 代替 REE

编辑:我注意到使用 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.

  1. Quit all processes that are accessing MacPorts files. You can see which ones are running with sudo lsof | grep /opt/local.
  2. sudo mv /opt/local /opt/localbak
  3. Open a new terminal, then compile and install REE
  4. 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

耶耶耶 2024-12-09 20:01:38

尝试添加:

IRB.conf[:USE_MULTILINE] = false

到您的 ~/.irbrc 文件,然后重新启动 irb(或运行 load '~/.irbrc'

Try adding:

IRB.conf[:USE_MULTILINE] = false

To your ~/.irbrc file, and restarting irb (or running load '~/.irbrc')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文