Speed up require on win32

Hello,

I am trying to speedup the ruby1.8.6 'require' function for Windows.
I've noticed that for file that successfully found FileMon reports too
many such errors:

DeviceIoControl, FAST IO DISALLOWED, Control: 0x12043
DeviceIoControl, INVALID PARAMETER, Control: 0x12043

One of the sources of these messages is:
win32.c > rb_w32_fclose > is_socket > getsockopt

I decided to reproduce this error. So, I wrote a test application linked
with msvcr80-ruby18-static.lib:

- - - - -
FILE * fp = fopen(fname, "r");
fclose(fp); // This results in rb_w32_fclose call.
- - - - -

But I do NOT get DeviceIoControl errors from my_test!

So in short
1. I get DeviceIoControl errors from rb_w32_fclose called by ruby.exe
2. I do NOT get DeviceIoControl from rb_w32_fclose called by my_test.exe
3. Errors come from the 'getsockopt' function.

Can any one explain this, please? How can we avoid errors comming from
ruby.exe?

Thank you,
- Alex

···

--
Posted via http://www.ruby-forum.com/.

Aha.. I forgot to call WSAStartup. No my_test.exe reports
DeviceIoControl errors too.

Btw, is not there any better alternative for 'win32.c > is_socket'
function?

- Alex

···

--
Posted via http://www.ruby-forum.com/.

My reply is over there in Usenet, apparently the attachment was too large:

http://groups.google.com/group/comp.lang.ruby/msg/8f85de91d3c3ba77

Cheers

robert

···

--
remember.guy do |as, often| as.you_can - without end

Hello, Robert

Your logs looks good.

I tested again in such environment:
OS: Vista
Process Monitor: 2.03
Ruby: 1.8.6, 1.8.7, 1.9.0

Used the same a.rb and command line as you. I got similar results for
all ruby versions: every successfull read of a.rb is followed by ~60
DeviceIoControl.

I can't attach my CVS (posting from google site). How did you attach
it?

- Alex

Hello, Robert

Your logs looks good.

And I also do not notice any slowdowns of require.

I tested again in such environment:
OS: Vista
Process Monitor: 2.03
Ruby: 1.8.6, 1.8.7, 1.9.0

My version was

ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]

Used the same a.rb and command line as you. I got similar results for
all ruby versions: every successfull read of a.rb is followed by ~60
DeviceIoControl.

Maybe it's in your environment? Do you somehow require "rubygems"?

I can't attach my CVS (posting from google site). How did you attach
it?

I sent it via Newsreader to the newsgroup comp.lang.ruby.

Kind regards

  robert

···

On 15.12.2008 02:20, getcha.2k8@gmail.com wrote:

Hi, Robert

ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]

Probably cygwin is not calling the same OS functions.

Maybe it's in your environment? Do you somehow require "rubygems"?

I tested on Windows Server 2003. And I tryed with/without rubygems -
same results.

Btw, I compiled ruby from sources, and changed rb_w32_fclose.

  //if (!is_socket(sock)) {
  if(1) {
    ...
    return fclose(fp);
  }

The DeviceIoControl lines are gone. Then I checked the speed. I
installed rails 2.2.2, then did:
1. irb -rubygems
2. s = Time.now; require 'activesupport'; e = Time.now; e.to_f - s.to_f

For normal ruby results was:
~ 1.16 sec

For patched ruby:
~ 1.00 sec

Not a big advantage, but any way. Going to see if in more complex
situations this can be more valuable...

- Alex

···

--
Posted via http://www.ruby-forum.com/\.

ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]

Probably cygwin is not calling the same OS functions.

Yes, that's a likely explanation.

For normal ruby results was:
~ 1.16 sec

For patched ruby:
~ 1.00 sec

Not a big advantage, but any way. Going to see if in more complex
situations this can be more valuable...

I don't think it's worth the hassle. Just my 0.02EUR...

Kind regards

robert

···

2008/12/17 Alex 2k8 <abc3def@gmail.com>:

--
remember.guy do |as, often| as.you_can - without end

I see the same issue here, with MSVC builds. However, with MingW
builds, i don't get the problem. The is_socket function you mention
has been changed significantly in 1.9.1 anyway.

···

On Dec 17, 4:26 am, Alex 2k8 <abc3...@gmail.com> wrote:

Hi, Robert

> ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]

Probably cygwin is not calling the same OS functions.

> Maybe it's in your environment? Do you somehow require "rubygems"?

I tested on Windows Server 2003. And I tryed with/without rubygems -
same results.

For normal ruby results was:
~ 1.16 sec

For patched ruby:
~ 1.00 sec

Not a big advantage, but any way. Going to see if in more complex
situations this can be more valuable...

- Alex

Submit a patch to core :slight_smile:
-=R

···

--
Posted via http://www.ruby-forum.com/\.

Submit a patch to core :slight_smile:

This was not a patch, just an experiment. I simply commented a call to
is_socket in rb_w32_fclose function. The 'require' works, but socket
related functionality whould be broken :slight_smile: And as for now I see no
significant improvements, not going to continue.

···

--
Posted via http://www.ruby-forum.com/\.