Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue for ocamlbuild on Windows #5201

Closed
vicuna opened this issue Jan 4, 2011 · 12 comments
Closed

Performance issue for ocamlbuild on Windows #5201

vicuna opened this issue Jan 4, 2011 · 12 comments

Comments

@vicuna
Copy link

vicuna commented Jan 4, 2011

Original bug ID: 5201
Reporter: daweil
Status: resolved (set by @damiendoligez on 2017-02-27T14:16:28Z)
Resolution: suspended
Priority: normal
Severity: tweak
Platform: Windows
OS: XP
OS Version: 2
Version: 3.12.0
Target version: later
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Related to: #4981
Monitored by: @gasche @ygrek Camarade_Tux @jberdine

Bug description

on Windows system, each command executed by ocambuild is encapsulated in a "bash -C" command which has a non negligeable overhead (~ 0.5s).
Unless the Filename.quote function is fixed, a simple improvement is to change a line in file ocamlbuild/my_std.ml,
In function sys_command, just replace the line
let cmd = "bash -c "^Filename.quote cmd in

by
let cmd = "sh -c "^Filename.quote cmd in

ocamlbuild will go much faster on Windows.

@vicuna
Copy link
Author

vicuna commented Jan 5, 2011

Comment author: ertai

In the same vein I would also be in favor of not calling the shell when the arguments are either easily quotable or need not to be quoted.

@vicuna
Copy link
Author

vicuna commented Sep 20, 2012

Comment author: daweil

and because ocamlbuild call the "bash" or the "sh" shell, ocamlbuild does'nt work when call direcly called from a DOS shell.
So this issue is not only a performance issue.

@vicuna
Copy link
Author

vicuna commented Sep 20, 2012

Comment author: @protz

Yes, however, the recommend way to run OCaml under Windows is inside a Cygwin environment (either with the cygwin-packaged ocaml, or the native win32 ocaml compilers) so that you have a shell and the gnu tools available to work with. Argument quoting is such a mess on windows that I don't think it would be easy to make sure ocamlbuild can rely on cmd.exe under windows...

@vicuna
Copy link
Author

vicuna commented Sep 20, 2012

Comment author: @ygrek

FTR see the discussion and referenced articles at https://forge.ocamlcore.org/tracker/?func=detail&aid=1170&group_id=54&atid=291

@vicuna
Copy link
Author

vicuna commented Dec 15, 2012

Comment author: Camarade_Tux

I've started to look at the issue a bit more in-depth.

ocamlbuild uses this for different kinds of commands:
1- calls to cp, rm, mkdir, find, ...
2- any command through "run_and_read" or "run_and_open" functions which start a process and retrieve its standard output

1- is probably the biggest performance killer by far, especially on windows. Spawning bash on msys or cygwin takes time and spawning another command will only be slower. These should be pretty easy to implement.

2- is more annoying. The functions "run_and_*" seem to be usable by plugins but maybe not officially (can someone confirm this?). Overall it would be nicer to avoid such functions or reduce their number (some are easy: there's a call to readlink).

There will still be a few calls ("ocamlfind list" for instance) anyway. In ygrek's link, thelema has implemented the necessary quoting in ocaml; would it be possible to include this in the standard library? Unix.exec* functions should also be rewritten to use that quoting.

Moving the run_and_* functions from ocamlbuild to the standard library would probably be good too since they're already in the ocaml sources and are needed by projects which cannot easily use an additional library (ocamlbuild, my yypkg package manager, probably omake, ocamlfind, godi, ...).

So, does removing as many calls to external commands as possible and adding support for proper quoting for processes in the standard library sound like a good way?

PS: this issue should be made linked to "#4981: ocamlbuild/my_std.ml shouldn't call bash" in mantis.

@vicuna
Copy link
Author

vicuna commented Jul 29, 2013

Comment author: daweil

I made some more test this last version of ocaml (4.01).

  • 30 s to compile my code on Windows, 10s on linux on the same machine.
  • With using "sh" instead of "bash" (or "bash --norc"), 20s to compile on Windows which is better thow twice slower than on Linux.

So, if bash cannot be removed, why not patching my_std.ml by "let cmd = "bash --norc -c "^Filename.quote cmd in" ?

@vicuna
Copy link
Author

vicuna commented Jul 29, 2013

Comment author: @gasche

I know nothing about Windows, so please bear with me if I have stupid
questions. I would be ready to add --norc as proposed (while removing
bash seems fishy), but I don't understand why this is need. My "man
bash" says:

An interactive shell is one started without non-option arguments and
without the -c option whose standard input and error are both
connected to terminals (as determined by isatty(3)), or one started
with the -i option.

[...]

When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if
these files exist. This may be inhibited by using the --norc
option.

My understanding is that by passing option -c as ocamlbuild already
does, we are not in the "interactive shell" case and --norc should not
be necessary. Am I wrong in this reading of the manual? Does
adding --norc really make a performance difference anyway?

@vicuna
Copy link
Author

vicuna commented Jul 30, 2013

Comment author: Camarade_Tux

Btw, quoting bash's manpage:
~/.bashrc if the shell is interactive. This option is on by default if the shell is invoked as sh.

Back to removing the need for bash, I've read specs and explanations more and I believe the only way is to rely on Unix.create_process* and not others.
Most of the process-spawning functions in ocaml call the system shell and going through cmd.exe seems quite pointless to me (or is the shell actually relied upon?) and currently, ocaml's lib has no function to do the kind of escaping that cmd.exe requires, leading to the use of bash to parse the command-line and escape arguments properly before calling our actual command.

@vicuna
Copy link
Author

vicuna commented Aug 1, 2013

Comment author: @gasche

I'm waiting for feedback from daweil on whether --norc really makes a difference.

@vicuna
Copy link
Author

vicuna commented Aug 1, 2013

Comment author: daweil

Yes, the --norc options makes a difference on Windows, but only 30% better, cf my note on July 29th.
But of course, if you can remove the call to bash, performance on Windows && Linux should be identitical. And the blog mentionned in #4981 : http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
could help to quote commands correctly for Windows instead of calling bash.

@vicuna
Copy link
Author

vicuna commented Aug 4, 2013

Comment author: @gasche

I committed the addition of the --norc option. I'm leaving the bug open as a place to welcome patches to remove some of the bash invocations in ocamlbuild (hint hint).

@vicuna
Copy link
Author

vicuna commented Feb 27, 2017

Comment author: @damiendoligez

ocamlbuild is now a separate project that lives on GitHub.
PR transferred to ocaml/ocamlbuild#171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant