irb: pasting in multiline irb is slow
Tried to paste a 31-lines snippet to compare a specific benchmark (anon module’s #inspect was incredibly slow in < 2.7.0).
What I found is that 2.7.0’s irb is unbearably slow to paste even these small snippet.
This is a comparison between Ruby 2.4.3 with pry 0.11.0 and Ruby 2.7.0-preview3 with irb 1.1.0:
I did some other tests:
- ruby-2.4.3 with irb-0.9.6 and ruby-2.7.0-preview3 with irb-1.1.0
--legacy: absolutely instantaneous; - ruby-2.4.3 with pry-0.11.0: almost instantaneous (I assume parsing for syntax highlighting takes some time); watch video above;
- ruby-2.7.0 with irb-1.1.0 and irb-1.2.0 (multiline mode): unbearably slow;
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 122
- Comments: 29 (3 by maintainers)
Links to this issue
Commits related to this issue
- [irb] Disable multiline support because it's slow https://github.com/ruby/irb/issues/43 — committed to swrobel/dotfiles by swrobel 4 years ago
- Disable 'mutliline' support due to poor pasting performance see https://github.com/ruby/irb/issues/43 — committed to acp-admin/acp-admin by thibaudgg 4 years ago
- Speed up pasting into irb/console by using newer bugfixed dependencies! https://github.com/ruby/irb/issues/43#issuecomment-758089211 — committed to sciencehistory/scihist_digicoll by jrochkind 3 years ago
I have the same issue with
multiline. An additional observation is that the “paste speed” slows even more as the whole payload is gradually pasted.I’m using;
Mac OS Mojave 10.14.6 (18G87)onMacBook Pro (13-inch, 2018)Terminalappzshas my shellrubymanaged viarbenvBelow is code that I see appear progressively slower on the screen with each line, when pasted in a single paste action. It takes ~12 seconds to completely paste this into the console.
The same full paste operation is instantaneous when using pre-multiline versions of
irb(such as1.0.0, or when runningirb --nomultiline.Workaround
For me, passing
--nomultilinewasn’t an option as I was running IRB via the Rails console. The configuration can be configured via an.irbrcfile instead;FYI, recent Rails can pass this option like so:
See https://github.com/rails/rails/issues/39909#issuecomment-666412792
I really am rather bemused by the approach here. Yes, I can completely disable all the new stuff in
irbbecause it’s cripplingly slow and it’s helpful to know how. But in that case, why does the feature even exist?Why is nobody talking about ways to fix the feature’s performance? We’ve had formatting and colouring engines for literally decades that ran many orders of magnitude faster; but it’s 2020, computers are almost unimaginably powerful and we don’t even need something to be coded that well, it just has to be coded to a decent standard.
This is not in any way an unreasonable expectation, surely? That a 2019 MBP 16" with the fastest CPU option should be slowed down to the point where you can watch it paint individual lines in a text only interface is surely acceptable performance for, well, nobody?
2.6.6 vs 2.7.1
irbjust on localhost is dreadfully slow.https://www.youtube.com/watch?v=gFHGwKzHY-4
Even with single line things like
puts "1", if I paste those in blocks with a keyboard shortcut and hold it down for autorepeat (as at the start of the video above, but with the multiline string excluded) then IRB under Ruby 2.7 is visibly much slower and, after I let go of the keyboard shortcut, keeps pasting for ages as the terminal is miles behind the keyboard buffer.It’s 2020 with multi-GHz CPUs and we can’t input characters into a terminal near-instantaneously? Something ain’t right
;-)@olliebennett workaround solved it for me. by default
railsc does not load any other .irbrc but from the current user’s home (~).so there are 2 ways
create a file in current user’s home (~)
cd ~to go to current user’s home (~) runvim .irbrcto create/open file add this lineIRB.conf[:USE_MULTILINE] = falsepressESCto enter command mode enter command:wq!to save and exittell application.rb file to load .irbrc from projects root folder create a .irbrc file in projects root with text
IRB.conf[:USE_MULTILINE] = falsetell application.rb to use this file instead usingload .irbrc file
I have the same problem… ruby 2.6 is almost instantaneous, 2.7 very slow, seems like each char is inputted individually.
I’m using Linux + Bash + rvm.
We can’t update to Ruby 3 quite yet but just adding
gem "reline", "0.2.2"to ourGemfilehelped tremendously.Thanks for the efforts with this!
Experiencing similar issues, sometimes strings don’t get pasted completely, even crashing irb with usually something like
/usr/share/rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/reline/ansi.rb:76:in 'block in cursor_pos': undefined method 'pre_match' for nil:NilClass (NoMethodError)Workaround from @olliebennett seems to help.
According to https://www.ruby-lang.org/en/news/2020/12/08/ruby-3-0-0-preview2-released/
This slow pasting issue is fixed in Ruby versions >= 3.0
I’ve released the new version of reline gem including ruby/reline#184 and ruby/reline#186 for speeding up. Please install with
gem install irb relineand check it.The IRB bundled with Ruby 3.0 had many bugs, so I fixed them and released irb gem 1.3.1 and reline gem 0.2.1. Please try them by
gem install irb reline.looks like this is fixed, closing it; thanks @aycabta and everyone who pitched in
I believe the issue is known upstream.
Even pasting a single line array with 10 hashes is visibly slow.
EDIT: improved benchmarking
ruby 2.7.2 with reline 0.1.5 takes around 2.9s ruby 2.7.2 with reline 0.1.8 takes around 0.7s ruby 2.7.2 with
--nomultilinetakes around 0.01sSo it improved a lot, but still feels not instant for this case.
And I can confirm what @jordan-brough wrote, pasting big hashes like from a JSON response is still really slow or locks up irb. In a really bad case with 200KB of JSON,
irb --nomultilineneeds 20s to paste it, while irb with reline 0.1.8 crashes after 2min withI have this issue too, like everyone, but even when it’s a single line — removing the newlines from the json block.
For whatever reason, the suggestions above didn’t work for me. So I wanted to offer another [roundabout] solution:
I simply created a json file and posted it to a cloud storage app (I used S3). Opened the file with
json = URI.parse('<url-to-the-file>').open { |f| f.read }. And parsed:json = MultiJson.load(json)(use whatever json tool you’re used to).It’s slower, but much faster than pasting 😱 Until this gets figured out, this will be my solution.
I’ve managed to reproduce this as well (iTerm2 on 10.14), except for me it alternates between pasting very slowly one character at a time (this bug) or crashing IRB entirely (#46) (and trying to run the paste commands in bash, which is super dangerous). This currently makes Ruby 2.7 completely useless for me, as I can’t easily change the IRB version back to 0.9.6 and can’t use any 2.7 consoles.
I sometimes have to paste the content of a spreadsheet column into IRB (don’t ask why … please, don’t 😖 ). With about 200 rows it takes way to long with syntax highlighting on.
Thanks @Faisal-nfl for the workaround! That helped me out for now.
I think that highlighting and multiline are a great addition to IRB and I hope we can find a way to get it up to speed in the future.
@StevenHarlow https://github.com/swrobel/dotfiles/commit/020485aac88045d8234a096fec11b51fb4a11f73
@rubyFeedback Is it logged anywhere?
Looking much better with the latest updates!
Retesting my previous example I get:
--nomultiline: 1.48sSo, still around 3.5x slower than Ruby 2.6.6 for me, but that’s so much better than the previous ~30x slower!
Copy-pasting this example code is still pretty bad for me.
On my computer:
40 seconds with multiline:
1 second without multiline: