Home Download Buy Blog Forum Support

Super Slow Ruby IO

Super Slow Ruby IO

Postby Phrogz on Fri Mar 19, 2010 4:52 pm

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

Code: Select all
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"


From Sublime's output:
Code: Select all
...
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?
Phrogz
 
Posts: 18
Joined: Tue Mar 02, 2010 4:21 pm

Re: Super Slow Ruby IO

Postby Phrogz on Fri Apr 02, 2010 4:12 pm

Two week ping.
Phrogz
 
Posts: 18
Joined: Tue Mar 02, 2010 4:21 pm

Re: Super Slow Ruby IO

Postby gpfsmurf on Mon Apr 05, 2010 5:48 pm

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.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Super Slow Ruby IO

Postby willi297 on Wed Apr 07, 2010 5:43 pm

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...
Greg Williams
Atomic Embedded, USA
http://atomicembedded.com
willi297
 
Posts: 121
Joined: Wed Nov 18, 2009 8:29 pm
Location: Grand Rapids, MI, USA

Re: Super Slow Ruby IO

Postby Phrogz on Mon Apr 19, 2010 3:51 pm

willi297 wrote: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.

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.


willi297 wrote: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...

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.
Phrogz
 
Posts: 18
Joined: Tue Mar 02, 2010 4:21 pm

Re: Super Slow Ruby IO

Postby willi297 on Tue Apr 20, 2010 11:52 pm

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.
Greg Williams
Atomic Embedded, USA
http://atomicembedded.com
willi297
 
Posts: 121
Joined: Wed Nov 18, 2009 8:29 pm
Location: Grand Rapids, MI, USA


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 9 guests