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
Compile non-speed-critical tools to bytecode only #11993
Conversation
|
My guess is that |
Native code (total 51ms):
Byte code (total: 80.3ms)
So in this case native code takes 64% of the time of byte code. |
I'm not suggesting we do this necessarily, but just to mention it: |
That's typical of programs that spend a lot of time in the runtime system. Computation-intensive programs are 2 to 10 times faster in native code. At any rate, we're seeing 10 ms gains in execution time. Is this worth the extra disk space used for the installation? Hard to know. |
I thought this trick was discouraged e.g. in GNU coding guidelines, but I can't find a reference. Also, does it work under Windows? |
Some people say disk is cheap and others like their builds to be as fast as possible. Both viewpoints seem unreasonable. In any case I'm not sure I care about these 10ms, you only get them on cold builds – after that they are cached away. I also suspect I'm the only person who actually uses That being said personally I'm not very fond of the mix of byte/native install this PR proposes but I can't exactly pin point what disturbs me, so why not. |
Why don't we just stop shipping Related : what about doing the same for ocamllex? This would also remove one binary from |
Alain Frisch (2023/02/06 12:48 -0800):
> > `ocamldep` is still compiled to native-code whenever possible, as this tool is heavily used and execution speed matters.
>
> I'm not suggesting we do this necessarily, but just to mention it: `ocamldep` is the same as `ocamlc -depend`, and it has been suggested in the past to install `ocamldep` as a link to `ocamlc` and have `ocamlc` act as `ocamldep` if `Sys.argv.(0)` matches `ocamldep`.
Why don't we just stop shipping `ocamldep` altogether and tell people
to use `ocamlc -depend`? Is it a backward compatibility concern /
support for multiple versions of OCaml? (Not shipping `ocamldep.opt`
anymore can also break existing build systems!) The transition could
be softened by instructing `dune` to use either `ocamldep` or `ocaml
-depend` depending on the version of OCaml; and/or providing an OPAM
package that installs an actual `ocamldep`.
Yeah, I had similar thoughts on this.
Related : what about doing the same for ocamllex? This would also
remove one binary from `boot/` (and reduce the "cost" of bootstrapping
in terms of increase in the repository size).
Here I do not understand, though. Are you suggesting to embed the
lexer in the compiler?
|
Frankly, I don't know. I don't feel comfortable with us doing choices of
this kind on behalf of the user, because even if the choices have been
thoroughly examined, to me they still carry something arbitrary and
hard-coded that I don't like too much.
Does the size of the installation matter so much that we need to do such
things?
To me this solution looks like a short-term hack to something where we
could make deeper progresses, e.g. not compile the FLambda middle-end
when it's not needed, try to work on compilerlibs so that `-linkall` can
be avoided, etc.
If we want control over what is compiled andinstalled, then I'd rather
see it takethe form of ability given to the user to enable/disable stuff
during configure, rather than us doing choices aon his/her behalf.
|
Yes, I was suggesting to embed ocamllex as a sub-command of ocamlc, like we did for ocamldep. I understand this is more controversial, since ocamllex is "less related" to the compiler than ocamldep. But in practice, ocamllex seems to be here to stay, and it induces some storage overhead in the source repository (as a bytecode in boot/) and in installations; so why not? |
I feel there's too much "whataboutism" in the comments and not enough reviewing of the actual PR.
This PR is a low-hanging fruit. With minor Makefile hacking (nothing worse than what @shindere has been feeding us with recently) we cut installation size by 13% without any user-visible change (except @dbuenzli losing a few tens of milliseconds in his uses of |
Our build rules rely on ocamlobjinfo to work out which transitive dependency libraries are exposed in interfaces, so we also rely on ocamlobjinfo in the hot path of our builds. Not sure whether using bytecode would be observable in our build times or not. |
Thanks for the data point. I'm OK with keeping a native-code build of ocamlobjinfo if you and @dbuenzli think it's safer this way. |
I’m not sure I understand the train of thought behind this change. If we want to make the installation smaller, why not just remove all the I have personally never seen those
|
On my current local install I also have 50Mo of |
Yes, this PR favors bytecode executables over native-code executables for non-speed-critical commands because, now that #11981 is merged, bytecode executables are consistently smaller than native-code executables.
Patiently waiting for the next "what about" comment... |
Makefile
Outdated
TOOLS_TO_INSTALL = \ | ||
ocamldep ocamlprof ocamlcp ocamlmklib ocamlmktop ocamlobjinfo | ||
# Tools to be compiled to native and bytecode, then installed | ||
TOOLS_TO_INSTALL_NAT = ocamldep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the convention that _NAT
means "both in native and bytecode" confusing. Could we:
- not use a prefix in this case, stick to
TOOLS_TO_INSTALL
,OCAML_PROGRAMS
etc. (the_BYT
would clearly mean "byte only") - or use
_BYT_NAT
or_BYT_AND_NAT
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel you're over-thinking it. I found it pretty clear and visually appealing to split X
into X_NAT
and X_BYT
.
for i in $(TOOLS_TO_INSTALL_BYT); \ | ||
do \ | ||
$(INSTALL_PROG) "tools/$$i$(EXE)" "$(INSTALL_BINDIR)";\ | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when INSTALL_BYTECODE_PROGRAMS is true, the layout we get is that foo.byte
and foo.opt
are available, and foo
is a symbolic link to foo.opt
. For bytecode-only programs I would expect to have foo.byte
available, and foo
as a symbolic link to foo.byte
.
If I understand correctly, this is not what this code does, it looks like it just installs foo
and not foo.byte
. Should we change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The .byte
/ .opt
/ symbolic link dance is intended to let users choose between the two implementations if they must, and pick the best implementation by default otherwise. If there's only one implementation, there's no choice to be made. Plus, there's @kit-ty-kate 's suggestion above to get rid of all this symbolic link nonsense, and I'm in favor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR, if users for some reason wanted to use a bytecode executable instead of its native counterpart, they would enable INSTALL_BYTECODE_PROGRAMS and then explicitly invoke foo.byte
. Unless I am missing something, your change breaks this use-case by making foo.byte
unavailable for some tools. (But then: maybe no one was doing that, and especially for those tools nobody cares about in practice.)
Independently of this backward-compatibility aspect, I don't see the problem with having a symlink. (My Linux box is full of symlinks all over, typically many of the /usr/lib/*.so
files are symlinks.) It arguably even adds discoverability, if I do ls -l .../bin/ocamlc
I can immediately tell that I have the native version on my system.
I also didn't interpret Kate's comment #11993 (comment) to be complaining about symlinks, I read it as suggesting that we install at most one version of each tool, with the absence of symlinks a side-effect of that (or in fact we could keep symlinks if we really wanted, but I agree that in this case it makes less sense).
To summarize: my opinion is still that having the symlinks would be nicer, and I think that they help with compatibility in INSTALL_BYTECODE_PROGRAMS mode. It would probably be okay (not my preference but okay) to do without the links outside the INSTALL_BYTECODE_PROGRAMS mode. Then we could discuss (in a separate PR?) disabling this mode by default, and we would get closer to your ideal world (with a configure option still working for .byte
aficionados).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced by your argument. For these rarely-used, non-performance-critical tools, I just want to go back to what we did in OCaml 4.02 and earlier. namely compilation to bytecode only and installation under the final name (no symlink to .byte
). So, we will agree to disagree here and try to move on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, if you insist, that works for me.
tools/ocamlcmt.opt$(EXE) "$(INSTALL_BINDIR)/ocamlcmt$(EXE)"; \ | ||
else \ | ||
$(INSTALL_PROG) tools/ocamlcmt$(EXE) "$(INSTALL_BINDIR)"; \ | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(removing this ad-hoc logic is a nice simplification)
Thank you my good sir. Done in edc4193 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to go with a Changes entry (we should let users know about the change).
There is an observable change in the installation layout of the tools affected by this change, even their bytecode version, which I think is un-necessary. But then we believe that these tools are almost never used, and probably not explicitly in their .btye version, so this is probably okay.
This reduces installation size.
By popular demand.
edc4193
to
64c6ccf
Compare
Currently, when native-code compilation is supported, the following auxiliary tools are compiled both to bytecode and to native-code, and both binaries are installed in $(PREFIX)/bin:
This PR proposes to not compile to native-code the following tools, and to install only a bytecode executable:
ocamldep
is still compiled to native-code whenever possible, as this tool is heavily used and execution speed matters. The other tools are rarely used and not speed-critical (to the best of my knowledge), so compilation to native-code is not warranted.(I'm not 100% sure about
ocamlcmt
; please contradict me if there are speed-critical uses.)The intent of this change is to reduce the size of OCaml installations further, now that #11981 is merged. On x86-64 linux:
CC: @shindere