Optimize for faster loading time and win32/file.c refactoring
This was originally discussed at [ruby-core:41799]
Best way to separate implementation specific code?.
Ruby startup time (loading time) is slow when loading a lot of libraries such as Rails. Some works were done to improve performance such as #3924, but startup is still not fast. Especially ruby on Windows seems much slower than on Unix like OS.
This work is an effort to improve startup time on Windows.
I have updated the patch with help from Luis Lavena. This patch improves loading time a little.
If load_path and loaded_features are large numbers such as rails app, file_load_ok() is called many times against non-existing path.
On Windows, GetFileAttributes() is faster than open(). And open() performance is affected by AntiVirus software's realtime scan.
I confirmed this with NOD32. Microsoft Security Essentials doesn't affect so badly as NOD32. It seems to depend on kinds of antivirus softwares.
Avoiding to call open() against non-existing path by using GetFileAttributes() seems to improve performance.
I used CreateFile() instead of open() because CreateFile() seems a little faster.
Here are rails startup benchmarks.
On Windows 7:
On Windows XP:
800ms improvement with NOD32 OFF
1800ms improvement with NOD32 ON
This fix would be helpful for windows users. I guess most windows users use antivirus softwares.
I confirmed make, make test are OK. make test-all result was same as before patch at the following revision.
ruby 2.0.0dev (2012-02-09 trunk 34511) [i386-mingw32]
At [ruby-core:41831], Matz agreed with replacing file_load_ok.
This is the first work in win32/file.c. The following works (optimize expand_path etc.) into win32/file.c will be done by Luis.
This patch changed configure and Makefile. I also confirmed make with
Is this acceptable way?