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
11
  • 5
    On my Mac text appears very slowly, but if I press any key it appears all at once. Try it
    – fl00r
    Apr 11, 2011 at 17:04
  • Does this happen in plain irb as well? Apr 11, 2011 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, 2011 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, 2011 at 18:22
  • @Rein, @Steve, @Tass, see edit to OP Apr 12, 2011 at 9:30

5 Answers 5

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.

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, 2011 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. Oct 24, 2012 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
2
  • Thanks. This is the only fix that worked for me with OS X 10.7 Lion. Mar 1, 2012 at 21:05
  • Same here using Ubuntu 12.04 with ree. jesvs' fix changed nothing for me. May 12, 2012 at 17:53
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.

1
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.

1
  • 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. :/ Apr 26, 2011 at 8: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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.