14

In one of my rails apps, the console has started running really slowly when i paste in text, type and (especially) delete text. I can see in top that irb is using lots of cpu. But i don't know how to diagnose this problem any further. It just started happening a couple of weeks ago. I'm wondering if it's possibly readline/wirble related? I use both of those.

I just tried it in another app, pasting in a block of text, and it seems just as bad - the text is appearing at the rate of one char a second! Maybe my command line history has filled up or something? How can i delete it? (for the rails console, not my bash command line history)

grateful for any advice - max

Edit - sorry, should have supplied some system details. Here you go:

System - Ubuntu 10.04
Ruby version - ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]

I just tried plain irb and i have the same problem. It might even be slower, it's pretty much ground to a halt halfway through the block of text i pasted in to test it.

I've rebooted many times (my laptop battery is knackered so i have to restart every time i unplug it anyway).

I'm not in a vm.

I have recently started using RVM (ruby version manager) and it seems to have coincided with that, though it might just be a coincidence. The problematic consoles are happening using system ruby, though, not an rvm.

Here's the output from ps aux | grep irb:

max      12583  0.0  0.0   1756   484 pts/7    S+   Apr11   0:00 sh -c irb  -r irb/completion -r "/home/max/work/rails_apps/millionaire_container/millionaire/config/environment" -r console_app -r console_with_helpers --simple-prompt
max      12584 15.9  2.7  61872 56956 pts/7    S+   Apr11 158:26 irb                                                                                                                                                                                     
max      13981 64.4  0.9  20080 18708 pts/9    R+   09:40  29:51 irb                          
max      14625 21.8  0.6  15020 12628 pts/12   Rl+  10:25   0:20 irb                                             
max      14757  0.0  0.0   3048   804 pts/13   R+   10:27   0:00 grep --color=auto irb
Max Williams
  • 32,435
  • 31
  • 130
  • 197
  • 5
    On my Mac text appears very slowly, but if I press any key it appears all at once. Try it – fl00r Apr 11 '11 at 17:04
  • Does this happen in plain irb as well? – Rein Henrichs Apr 11 '11 at 17:13
  • @Max -- you didn't say what OS or version you were using, but I'd start with a plain ps aux from the command line to see what's in the working set. Or just reboot and see if the problem goes away. Watching the Mac Activity Monitor (if you are on a Mac) might give you some clue -- watch cpu and/or watch disk activity. – Steve Ross Apr 11 '11 at 17:37
  • My question would be this. Are you working inside a virtual machine? I am, and have found that processes in my host operating system (namely add-ons or extensions for FireFox) will eat up CPU cycles. This then causes my virtual machine to be sluggish. – Tass Apr 11 '11 at 18:22
  • @Rein, @Steve, @Tass, see edit to OP – Max Williams Apr 12 '11 at 09:30
  • Little offtopic. Why do you use such an old Ruby version? – fl00r Apr 12 '11 at 09:32
  • How much text are we talking? – Dogbert Apr 12 '11 at 09:32
  • @Dogbert - 3135 chars, so not that much. It is all one one line but even if i split it into several lines before pasting it's really slow. It's not just pasting text though - just normal typing and especially deleting characters in console can be incredibly slow sometimes - eg 2 sec gap between deleting characters. – Max Williams Apr 12 '11 at 10:32
  • How about pasting the text in a text editor like nano, is that also slow? – Jonas Elfström Apr 12 '11 at 16:03
  • Sorry to be so late but... couple of questions: Are you running the Ubuntu box or are you ssh'ed into it? If ssh'ed, what terminal program are you using? I just got iTerm2 on my Mac and some terminal stuff can be pretty pokey. – Steve Ross Apr 15 '11 at 04:45
  • I never really fixed this, but i now use rvm for all my projects so it's not an issue - it's fine in an rvm, it's just system ruby that's slow. – Max Williams Jul 20 '11 at 16:24

5 Answers5

17

It seems like rvm's readline is causing the slowness, put this line in your ~/.irbrc:

IRB.conf[:USE_READLINE] = false

Now try pasting something on irb. Is it fast? Good!

Only problem now is that you've lost the ability to edit your lines. We need to fix rvm's readline.

# assuming 1.8.6 is your rvm's default ruby version
rvm package install readline
rvm remove 1.8.6
rvm install 1.8.6 --with-readline-dir=$rvm_path/usr

Don't forget to edit out the IRB.conf line from your irbrc.

jesvs
  • 171
  • 2
  • It works, but now I lost the hability to use arrow up to execute previous commands... Any fix that solves that?? – iwiznia Dec 15 '11 at 11:20
  • Somehow, --with-readline-dir is not recognized by the configure script of ruby-1.8.7-p371, so I have to use jordoh's solution to get ruby 1.8.7 to use libreadline 5.2. – David Grayson Oct 24 '12 at 23:37
4

Simply using readline didn't help for me; there seems to be a deeper problem with libreadline, at least on OSX 10.7 where the select() system call waits for the timeout to expire before returning, even when there's data available.

My hack, which fixes this annoyance, is:

cd $rvm_path/src/readline-6.2
vi config.h
(change the line "#define HAVE_SELECT" -> #undef HAVE_SELECT)
make install
Osheroff
  • 381
  • 2
  • 3
3

I ran into the same issue using REE on Ubuntu 12.04 and tried all the solutions listed here without any success. The final working solution for me was:

  1. apt-get remove libreadline6-dev
  2. apt-get install libreadline-gplv2-dev
  3. rvm remove 1.8.6
  4. rvm install 1.8.6

The issue appears to be a minor incompatibility with libreadline6-dev. When libreadline6-dev was present on the machine, it would be used when compiling Ruby, and the problem would occur. This would happen regardless of the --with-readline-dir options passed when compiling ruby. Unfortunately, in the latest version of Ubuntu, there is no libreadline5-dev, but there is libreadline-gplv2-dev.

jordoh
  • 66
  • 2
  • Some additional details for those running versions of Ubuntu older than Oneiric http://www.williambharding.com/blog/rails/fix-irb-pasting-is-super-slow-typing-in-ruby-debugger-has-lag/ – wbharding May 30 '12 at 01:22
0

FWIW the fix suggested by @fl00r does indeed work. For me, this new behavior appears to correlate with installing the Snow Leopard 10.6.7 update. It happens in both IRB and Rails Console.

Another thing that seems to work for me is to make sure the last line of the pasted test includes a "naked" newline character.

This is definitely new behavior and it is very annoying.

  • hi rantler. I'm using ubuntu, not mac. I haven't done any upgrades. Also, this problem occurs not just with pasting text but with normal typing and deleting of characters. :/ – Max Williams Apr 26 '11 at 08:29
0

I see it on OS X too. @fl00r's fix works (hitting any key while the paste is trying to, um, paste.) @jesvs fix works and is permanent.

Bill Burcham
  • 739
  • 5
  • 12