Sublime Forum

Super Slow Ruby IO

#1

Compare the speed of this script run from cmd.exe versus using Sublime’s Ruby build target:

[code]C:>type tmp.rb
t = Time.now
1.upto(1000){ |i| p i }
p Time.now - t, RUBY_VERSION, RUBY_PLATFORM

C:>ruby tmp.rb

999
1000
0.069
“1.9.1”
“i386-mingw32”[/code]

From Sublime’s output:

... 999 1000 35.39 "1.9.1" "i386-mingw32" [Finished in 35.756 seconds]

That’s…a really big performance hit to print things to STDIO. Any way it can be fixed?

0 Likes

#2

Two week ping.

0 Likes

#3

If the problem comes from the I/O, you could try writing the output to a scratch buffer instead.

For an example on how to do this, check the “runPerl” function of the PerlTidy plugin. It runs a Perl script and writes the output to a new scratch buffer, you can easily adapt it for Ruby.

0 Likes

#4

I run Ruby through sublime quite a bit. I believe that the debug p() method flushes stdout after each write to it. If you just do puts instead, you will likely see a bit improvement in performance, you just won’t see live updates as they happen. I would add a periodic flush of stdio to compensate for that issue.

You’re running an interpreter in another interpreter that is dumping the output to a control that is repopulated with interpreted python. You can’t really compete with a raw C/C++ console with this setup…

0 Likes

#5

Thank you for your reply. I’m a needy bastard who’s not interested in finding hack workarounds, but want it fixed in the tool itself. I understand that reducing the number of IO hits will help this. I want it to just work, however.

I think you can come close enough. Certainly closer than 35.7ms for each IO hit.
The same program run in ‘e’ text editor, which is running the ruby script inside another ruby script under cygwin, and using the owning ruby script to capture the output and convert to HTML, which is being rendered and re-rendered by Trident to show the output, finishes in 0.008s. There’s no need for Sublime to be over 4,000 times slower for capturing a line of flushed text and adding it to a console.

0 Likes

#6

Yeah, the IO speed should be fixed, cuz it’s a pain to deal with. Especially when you are running Ruby code where you have no control over (or don’t wanna hack up). I’ve really noticed no real performance issues with Ruby I/O in Sublime though. Maybe I will try running your test when I get some spare cycles. I am running Ruby 1.8.7 btw.

0 Likes