Project

General

Profile

Actions

Feature #5999

closed

Optimize for faster loading time and win32/file.c refactoring

Added by h.shirosaki (Hiroshi Shirosaki) about 12 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
[ruby-core:42480]

Description

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.

https://gist.github.com/1605263#file_0001_move_rb_file_load_ok_to_win32_file.c.patch

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.

Benchmark:
https://gist.github.com/1605263#gistcomment-75650
https://gist.github.com/1448652

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:

200ms improvement
https://gist.github.com/1605263#gistcomment-82137

On Windows XP:

800ms improvement with NOD32 OFF
1800ms improvement with NOD32 ON
https://gist.github.com/1605263#gistcomment-75644

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 nmake(mswin32).

Is this acceptable way?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0