41

What are the specific technical causes of Ruby being so much slower on Windows? People report about a 3X speed drop from Linux/OSX and there are some vague discussions about Ruby using a compiler for Windows versions that produces slow code but I can't find any specific details.

Anybody know the specifics? I'm not interested in hurf durf Windoze sucks yuk yuks.

August Lilleaas
  • 51,168
  • 11
  • 94
  • 107
srboisvert
  • 12,479
  • 15
  • 61
  • 85

6 Answers6

25

I would guess there are a few possible options, and they probably all add up:

  1. Ruby being mainly developed on Linux, it ends up mechanically optimised for it. The code is regularly tested for Windows and everything works, but the result is still that developer will spend more time optimising for Linux than Windows.
  2. To my experience, recent versions of gcc (4.3 and greater) produce code more efficient than recent versions of Visual Studio (at least 2005). My tests included in both case spending about a day finding the best options for code optimisation.
  3. Related to point 1, if you compile the same project using gcc for Windows or Linux, I usually observe a drop of performances of about 20% on Windows compared to Linux. Here again, I suppose this is because Linux (or Unices in general) is a primary target for gcc, windows is a port. Less time is spent optimising for Windows than Linux.

In the end, if one would want to optimise Ruby for Windows, a significant amount of time (and money, as far as I know, profilers on Windows don't come for free) will have to be spent using a profiler and optimising bottlenecks. And everything will have to be tested on Linux to make sure there is no loss of performance.

Of course, all than should be tested again with their new interpreter YARV.

Steven Penny
  • 82,115
  • 47
  • 308
  • 348
PierreBdR
  • 38,125
  • 9
  • 41
  • 60
  • 4
    Both AMD CodeAnalyst and Intel's Vtune are available for free :-) – Jasper Bekkers Jun 02 '09 at 11:15
  • Ad 3. There is no difference in optimizing code for Windows or Linux only hardware platform change can make a difference. – lispmachine Jun 04 '09 at 10:24
  • 4
    VS8/9-built MRIs are slower than MinGW-built MRIs. Last I checked, the official Windows binary was built with VS6, which is even slower; that was a while ago, though. I switched to JRuby for Windows and didn't look back. – user60401 Jun 04 '09 at 14:02
  • 1
    As a point of reference, I went to RubyConf 2013, and I don't recall seeing even one computer that wasn't a mac. I heard a rumor that there was a linux laptop, but it might have been linux running on a macbook. – DGM Dec 28 '13 at 14:33
16

I've not done much work with the source code of the YARV interpreter, so the following comments pertain only to the 1.8.6 MIR interpreter.

In the course of trying to write a C extension for Ruby in Visual Studio, I discovered to my horror that the downloadable Windows binaries of Ruby 1.8.6 are compiled using Visual C++ 6.0, which was released shortly after the end of the Second World War. Since then compilers (and the processors they target) have advanced considerably. While the Linux builds get the latest gcc goodness, the Windows build limps along with last century's compiler technology. That's one reason. (Disclaimer: supposedly 1.9 is to be built with mingw, of which I am not a fan, but which also must be better than VC6)

Without knowing what ops in particular you find slower on Windows it's hard to comment further, but I will note that I found the I/O implementation on Ruby to be considerably less performant with both network and local file I/O. I never delved into the implementation of the I/O primitives enough to see why, but I assume the implementations assume the fast IO constructs on Linux are the fast IO constructs on Windows, which is almost always not the case.

anelson
  • 2,509
  • 1
  • 16
  • 27
3

Not completely to your question, but there was a great discussion on the Deep Fried Bytes podcast that discussed the same question in the IronPython context. I understand your question pertains to Ruby, but there may be related issues that also affect Ruby.

Also, the discussion does a good job of looking a bit deeper than "Windows sucks", so it's worthwhile to check it out.

Thorsten
  • 12,213
  • 16
  • 58
  • 79
2

At first you need to make a distinction between the older MRI interpreter (versions up to 1.8) and the newer YARV, which is the official interpreter for Ruby 1.9. There are big performance improvements and a different design in Ruby 1.9, so one needs to know which version you are talking about. I am guessing that what you've read refers to 1.8.x version, which is the only one that has an one-click installer so far.

Also, it would be good to know if you are talking about Ruby on Rails performance or Ruby in general. I know that there should be a clear distinction between these two, but because Ruby on Rails is the main use of Ruby, people often talk about its performance as if they were speaking about Ruby's performance.

As for the compiler, Ruby can be built using any recent version of Visual Studio, which is more than fine. I guess that if such a performance difference does exist, one should look at the implementation of the interpreter and see if there is something that would make a difference between a POSIX and a Windows system.

kgiannakakis
  • 96,871
  • 26
  • 155
  • 191
  • 2
    Ruby 1.9 (with YARV) is still much slower on Windows. (Note that I haven't actually done any benchmarks, that was just my unscientific observation.) – Sasha Chedygov Jun 04 '09 at 22:14
1

The performance bump is not 300%, in general, instead, it is closer to 50%-100%. Casual Jim's explanation is one of the reasons why data processing scripts are slower on Windows compared to Unix-variants and Linux.

In the more general case, the only thing I can think of is that Ruby development is Linux-centered, which has lead to many Unix-isms in the way Ruby was built. Also, since most active developers are not Windows users, very little Windows optimization expertise is present in the team, and most performance optimizing decisions are focused on making things faster on Unix systems.

A specific example of this is that Ruby uses copy-on-write parameter passing, which, according to what I read, can't be done properly on Windows, causing a lot of overhead in method calls.

I can't seem to figure out though, what Casual Jim did to deserve the -8 vote.

wvdschel
  • 11,590
  • 14
  • 38
  • 44
-1

ntfs automatic file compression on windows was slowing up everything for me. it starts working automatically when you are low on hd space... and then it needs to decompress and recompress files on the fly, as you access them, wasting cpu cycles..

Run the following command to uncompress a whole ntfs drive from its root (i.e. "C:\") and see if there are any differences, to me it made a huge difference and got ruby/rails speed back to what i was used to before !

command is:

compact /u /s /i 
BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
jj_
  • 2,548
  • 28
  • 55
  • Is this....safe? What are the possible side effects? I ask because I've spent/wasted so much time trying to build/remote to/use WSL/etc for ruby that i finally decided it wasn't worth it and to just deal with the slowness on windows. But if i could speed it up, that'd be the ideal. (WSL has its own complications and i just want to use one environment and be done with it.) – Max Cascone May 20 '19 at 18:26
  • Why wouldn't it be safe? I think you should only make sure you have the required free space. On the other side, I don't think Windows would let you complete the process for those files that when uncompressed would grow over that available free space. So the worst case would be that some compressed files could not be uncompressed. Also I am pretty sure there could be specific tools aimed exactly at managing native windows compression on a greater level of detail, allowing you to manage which files to decompress and which not. – jj_ May 20 '19 at 23:12
  • Because it's messing with the disk-level settings of my entire drive? And it doesn't really seem like the root cause of ruby-on-windows slowness? – Max Cascone May 22 '19 at 03:41
  • @MaxCascone did you read my whole comment? Because I fully elaborated on what you asked about safety concerns. However in your followup comment you just came up with rhetorical and polemically toned questions, embedding your own answers. So why did you ever ask in the first place if you got your good answers already? I was just trying to help. Also, I never said my solution would fix `the root cause of ruby-on-windows slowness`. I just said it worked for me. Learn some manners dude! This is not the typical forum you might be used to, and this kind of attitude is not very well tolerated here! – jj_ May 24 '19 at 05:22
  • It's my fault for reviving a seven-year-old thread. I admit i was a bit rushed at the time and fired off the follow-up questions without fine-tuning my approach. If you take an objective look, I think you'll realize that you responded with several ad hominem attacks and accused me of being rude and argumentative, when I would say you escalated the tone in this thread without any provocation from me. I agree that SO is a place of learning and I always strive to be as respectful and helpful as possible; maybe I missed the mark on this one, and I suggest you reflect on your own reaction as well. – Max Cascone May 24 '19 at 14:47