Conversation
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16328 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
…e optimizations prudently turned off. Auxiliary changes: - Put GCC in gnu99 mode (= C99 + GNU extensions). - Check C99 conformance, warn if not. - Reject if gcc is too old ( < 3.0 ) - Stop C compilation on warnings if this is a development version of OCaml. (I'm tired of C warnings being ignored.) git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16329 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
The intent is to produce fewer warnings when configuring with -verbose. Note that the warning on "implicit declaration of function" remains, for relatively good reasons. git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16330 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
|
I am in favour. Previously, when I looked at this, I also came to the conclusion that -fwrapv -fno-strict-aliasing seemed to be the correct set of options to use. I seem to recall that my experiments didn't show much of an increase in performance for native code. We have some better benchmarking infrastructure at Jane Street these days though, and we can try the tests again. |
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16331 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
|
I like this too. Note that there's another ticket somewhere about using SipHash in the stdlib. It has similar performance characteristics compared to the current hash function if the code is compiled with one specific optimization. In other words, there's a use for that in native code too but currently it's waiting for higher level of optimizations to be used to build the runtime. I'd prefer to see more warnings enabled rather than have -Werror. For instance, -Wextra and -Wwrite-strings are very interesting (and another dozen ones which I don't have off-hand but should be debated in any case) . However I fear that adding -Werror now will hinder enabling additional warnings: noone will want 40 new warnings and -Werror both at once. -Werror could be added a couple months after the warnings for instance. An alternative could be -Werror=Wall if that works for "meta" warning options (i.e. that it doesn't require specific warnings to be effective). Should we have some kind of benchmark in the source tree for that? Optimizations in GCC and LLVM are very variable wrt. versions or C code and it would be good to be able to track this easily. I also fear that js_of_ocaml people will complain because the bytecode interpreter is getting faster compared to jsoo's output in web browser. :P (just kidding obviously) Your benchmarks show a nice gain for the interpreter but that doesn't mean the same gains exist for C stubs. Unfortunately this change will trickle down to other peoples' bindings and I'm a worried about the number of possible failures there (sometimes for code that hasn't been actively maintained for years). Do you think it would make sense to have something less aggressive like -O2 (and warnings) for stubs instead? edit: GCC is c11 or gnu11 now too; surprisingly it seems to not break many things (the switch to C++11 however...) |
|
how will it affect the compile time of building a compiler, can we turn -O when in dev mode? |
|
Xavier: (prompted by what adrien-n writes) if I remember correctly, it is possible to pass C files to the OCaml compilers, which will then invoke the C compiler. Does your change affect the optimization flags that will be used in such a situation? I'm not sure whether we should do that. Although one might argue that if these flags are safe for the runtime, they are very likely safe for Joe Bloggs's C stubs. |
|
Mark: I don't believe the optimization passes of GCC are buggy, I believe the Joe Blogg's C stubs are. :P As for the compile time, -O3 can be quite slow but this mostly happens with large(r) compilation units. If you want to save time on that front, you should try ccache: it's a small (5% or so) overhead with an empty cache and then it runs 50 to 100 times faster than an actual compile. In other words you won't spend more time on the initial build but then it will be much faster. |
|
Concerning At any rate, I am adamant that no C code that triggers a |
|
Concerning C stubs in third-party libraries, there are two ways to build them: or In the first case, the third party is in control of flags. In the second case, the C compiler flags used to compile OCaml (technically, Higher optimization does expose bugs in C stub code. Indeed I found one this way in the Unix library: 0178ea4 It's not a bad thing: latent bugs are bugs; the earlier they are exposed, the earlier they are fixed. The one thing I'm uneasy about is to force |
|
Concerning warnings beyond |
|
Concerning the time it takes to compile the OCaml sources, I noticed no significant slowdown by using As to using |
|
Concerning
Among the optimizations that |
|
Concerning benchmarks, some of the tests in testsuite/ are actually suitable as micro-benchmarks. But what we want is macro-benchmarks obtained on real applications. Since real applications have dependencies, I think it's a job for OPAM: just like some packages have test suites, it should be possible for a package to expose a "make benchmark" script that OPAM could call. |
… compiling a C source file. The risk of breakage of 3rd-party libraries is too high. There might be cleaner ways to achieve this effect, e.g. split BYTECCCOMPOPTS into BYTECCCOMPOPTS and BYTECCEXTRAWARNINGS. git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16337 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
|
I don't know if this is the right place to start warning but using |
|
Yes, it is exactly the place. Thanks for the info. I'm fine with being prudent and use |
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16338 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
|
I had a look at the difference in The new pass in The other worry is |
|
Sobering news about If we decide to go the way of this PR, we should merge it on trunk early, well ahead of the next release, so that it gets widely tested. |
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16375 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
configure: uninitialized variable $nativeccprofopts git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cc-optim@16377 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
|
I went ahead and merged in trunk, SVN commit 16379, so that it can get extensive CI testing. In case of problem, there are 2 lines to change in configure to go back to the old behavior. |
|
Commenting a bit late on this (just learned about it on caml-list). Are you aware that Another option exists, |
|
Thanks for the info about -fwrapv. After chasing the links you give, it seems to me that -fno-strict-overflow was introduced (in gcc 4.2) at the same time as the -fwrapv problems were fixed... So, I don't see the benefit of using -fno-strict-overflow instead of -fwrapv if gcc's version is >= 4.2. More generally, ocaml's runtime system, especially the bytecode interpreter, require twos-complement wrap-around on overflow to function properly. So it makes sense to inform gcc of this fact by putting -fwrapv. The remaining question is: should we reduce optimization level (to -O1 instead of -O2) if GCC is older than 4.2? That could make sense. |
|
MPR#7452 (Compiler segfault on large generated source code) seems related to runtime optimization levels: the segfault cannot be reproduced with an |
|
Evidence for MPR#7452 points to a hardware issue. |
Multicore-safe implementation of Lazy
* also: upgrade node version now that Vercel has node version 14.x available
- Remove uninteresting or not well defined complexities (length, finding an element) - Rename "accessing cell `i`" into "random access" - The "adding an element" complexity for Hashtbl and Buffer was wrong
Currently, the run-time system and the C stub code are compiled at a conservative
-O(=-O1) optimization level. This pull request investigates the use of higher optimization levels.Optimization level
High optimization levels are risky, because optimizing C compilers assume that the C source is free of undefined behaviors w.r.t. the ISO C standards, and optimize accordingly. There are two main sources of such undefined behaviors in the OCaml sources:
double *pointer and anint *pointer never alias. This may not be safe for the OCaml runtime system, because it makes a lot of casts between thevaluetype and various pointer types.Consequently, I propose to use
-O3optimization level but tame it by selecting-fwrapvto tell the compiler we expect signed integer arithmetic to overflow and to wrap around;-fno-strict-aliasingto turn off type-based aliasing analysis and tolerate wild pointer casts.These options are supported by Clang and by GCC (since version 3.4). On other compilers, the configure script selects
-Ooptimization, like before.Performance impact
The impact of these optimizations on OCaml performance is important for the bytecode interpreter, and barely noticeable for natively-compiled programs.
Compiling
ocamlrunwithgcc -O3instead ofgcc -Ospeeds up bytecode interpretation by a factor 1.2 to 2.2 (!) on small bytecoded benchmarks, 1.3 on a larger program (CompCert). This is primarily due to better code being generated for theNextmacro of the bytecode interpreter. (gcc -Opessimizes this macro; higher optimization levels do the right thing.) Withgcc -O2, performance is almost as good.The same small set of benchmarks compiled in native code show no significant speedup or slowdown when the runtime system is compiled with
gcc -O2, and a barely significant 1.03 speedup when the runtime system is compiled withgcc -O3.My small set of benchmarks doesn't exercise much of the runtime system. Other measurements are needed.
Other proposed changes
These changes are unrelated to optimization but affect the
configurescript as well.gnu99(= ISO C99 + GNU extensions) mode instead of the defaultgnu89(= ANSI C + GNU extensions) mode. I want to encourage the use of C99. Besides, clang isgnu99or evengnu11by default, so GCC/Clang portability is increased. As to why GNU extensions and not strict ISO C mode, some useful libc functions are not declared in standard includes in strict ISO C mode.-Werror(treat warnings as errors). The warnings emitted by GCC and Clang in-Wallmode are almost always indicative of a C programming error. I'm tired to see these warnings ignored by OCaml developers who touch the runtime system.-Werroris selected only for development versions of OCaml (with+devin the version string), but is turned off for released versions. We must fix warnings during OCaml development, but released versions may be compiled in nonstandard C environments that we never tried, so they should have a chance to compile even with some warnings.