From: Johan Holmberg Date: 2001-12-07T03:48:40+09:00 Subject: [ruby-talk:27728] File IO very slow on Windows ("i586-mswin32") Hi ! Ruby built natively for Win32 is very slow when reading large files. I use 1.6.5 built on "i586-mswin32". Recently I had a little program essentially containing just a loop like while line = gets ... end When I ran this script on a file looking like: $ wc foo.log 19130 692976 16813844 foo.log it took about 90 seconds. This seemed very strange. So I recoded the script in Perl. Result: 2 seconds. Quite a difference ... I also tried the two scripts on Solaris, to see if the problem was Win32-specific. Result: Perl: 2 seconds Ruby: 12 seconds Not so good for Ruby, but not as bad as on NT. Finally I tried to look in the Ruby code, to see where the time is spent. After a while I found a section in the function 'rb_io_gets'. I tried to comment out a couple of lines: ------------------------------------------------------------ *** io.c~ Wed Sep 5 07:53:28 2001 --- io.c Thu Dec 6 18:24:18 2001 *************** *** 746,755 **** --- 746,759 ---- again: bp = buf; for (;;) { READ_CHECK(f); + #ifdef KOKO TRAP_BEG; + #endif c = getc(f); + #ifdef KOKO TRAP_END; + #endif if (c == EOF) { if (ferror(f)) { if (errno == EINTR) continue; ------------------------------------------------------------ After this change, the script took 4 seconds (instead of 90 as before). TRAP_BEG implies that for example the Win32-function 'InterlockedExchange' is called *once for each character* as far as I can see. This seems totally insane ... Is this an already known fact ? Is anything being done to fix it ? Recently there has been talk of using Visual C++ (or another "native" compiler) for the Win32 version of Ruby. I suppose things like this has to be dealt with before Ruby can be used seriously on Win32 (and I very much want that to happen). Regards, Johan Holmberg