Skip to content

Very slow on startup #448

@hyrious

Description

@hyrious

I'm not sure if this is the right place to ask...

It takes at least 1 second to start ruby.exe on my PC while it starts instantly on other OS. So I opened process monitor to see what actually happens:

Image (runs ruby -e 1)

  1. My ruby's arch is x64-mingw-ucrt.
  2. It is obvious that ruby loads its stdlib on start, there're a lot of files. For each file, it seems ruby.exe will query fs info of every parent path to get a normalized path.
  3. There're a lot of duplicated works, the CreateFile .. CloseFile pattern occurs about a hundred of times to test the same folder. Each task is very quick, but when there're 100 tasks it will cost > 1 second.

Additional contexts:

  1. I noticed that this code in ruby's source code may be doing these path checking works.

  2. For comparison, I also profiles node.exe -r ./a.js, which is quite fast:

    Image

    The reasons behind, which I could come up with, are that:

    • node.exe intentionally bundles all it's stdlib into the binary, that reduces a lot of time to load the hundreds of files.
    • As of loading a single file, node.exe does very little work (4 winapi calls) where ruby.exe does a lot (8 * N calls (where N is the dir depth of a file path) + 1 CreateFileMapping which seems to lock the readers of a file).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions