7 ms·
> Damn, are we doing this wrong? Yes, and I mean "we" as in "this industry". I just recently talked to someone whose Swift framework(s) were compiling at roug
by mpweiher 9y ago
> Damn, are we doing this wrong?
Yes, and I mean "we" as in "this industry".
I just recently talked to someone whose Swift framework(s) were compiling at roughly 16 lines per second. Spurred on by Jonathan Blow's musings on compile times for Jai[1], I started tinkering with tcc a little. It compiled a generated 200KLOC file (lots of small functions) in around 200 ms.
Then there are Smalltalk and Lisp systems that are always up and pretty much only ever compile the current method.
We also used to have true separate compilation, but that appears to be falling out of favor.
Of course none of these are C++ and they also don't optimize as well etc. Yet, how much of the code really needs to be optimized that well? And how much of that code needs to be recompiled that much?
So we know how to solve this in principle, we just aren't putting the pieces together.
[1] https://www.youtube.com/watch?v=14zlJ98gJKA https://www.youtube.com/watch?v=14zlJ98gJKA He mentioned that a decent size game should compile either instantly or in a couple of seconds
- pjmlp 9y agoBjarne's made the mistake of having C++ rely on C's linker model, so it meant no modules. Now we can see it as a big mistake, but on those days probably it was one of the reasons why C++'s adoption took off. Also while C lacked modules, most Algol and PL/I derived languages supported them since the late 60's. Swift's case has the issue of mixing type inference with subtyping, so lots of time is spent there. All in all, I really miss TP compile times and at least on Java/.NET, even with AOT compilers are close enough. EDIT: some typos
- ajross 9y agoStraightforward integration with existing tooling was not a "mistake", it was a design point. There were plenty of competing runtimes even in the 80's that were better than C's linker model. C++ succeeded because it didn't create that friction.
- pjmlp 9y ago> "but on those days probably it was one of the reasons why C++'s adoption took off." I know "Design and Evolution of C++" quite well, and have been a C++ user since Turbo C++ 1.0 for MS-DOS.
- ajross 9y agoSure, but it wasn't a "mistake". Stroustrup absolutely wanted a C with classes, and that meant tight integration with C toolchains. Symbol mangling was the clever idea invented to implement that very deliberate choice, not a fortuitous happenstance.
- pjmlp 9y agoActually name mangling predates C++.
- CodeMage 9y agoI'm pretty sure @pjmlp is using the word "mistake" to say "a decision that turned out to be bad". English is not my native language, but judging by the ways I've seen it used and what dictionary definitions I can find, it seems quite acceptable. Stroustrup made the decision on purpose and consciously, but it turned out to have disastrous effects.
- pjmlp 9y agoYep, you got it right.
- rwmj 9y agoOCaml uses C's linker model, and yet still manages to have working Modula-like modules (even with cross-module inlining). So there's an existence proof that it's possible to do it well.
- pjmlp 9y agoWhere can I learn more about it in a high level way instead of delving into source code? I am curious how it is done in a portable way across all OSes, specially crude system linkers and OSes without POSIX semantics. For example, I imagine this can be made via ELF sections, but not all OSes use ELF.
- qznc 9y agoMy guess: The trick is not to have "template instantiation" but "module instantiation" (aka Functors in OCaml). Now you can instantiate only once. For example, if the compiler encounters "List<Foo>", it would instantiate into the "List$Foo.o" file or not if it already exists. Java works similarly, except the files have the extension "class" instead of "o". More generally speaking: The trick must be to not generate identical instantiations multiple times. So you must have a way to check, if you already generated it. Of course, the devil is in the details (e.g. is equivalence on the syntactic level enough?).
- pjmlp 9y agoYou are focusing only on generics and missing all the module metadata and related module type information. In module based languages, the symbol table is expected to be stored on the binary, either to be directly used by tools or to generate human readable formats (.mli). So if one uses the system C linker, it means being constrained to the file format used by such linker.
- rwmj 9y agoThese links explain the extra files: https://ocaml.org/learn/tutorials/filenames.html https://ocaml.org/learn/tutorials/filenames.html https://realworldocaml.org/v1/en/html/the-compiler-frontend-parsing-and-type-checking.html https://realworldocaml.org/v1/en/html/the-compiler-frontend-... https://realworldocaml.org/v1/en/html/the-compiler-backend-byte-code-and-native-code.html https://realworldocaml.org/v1/en/html/the-compiler-backend-b... The cmx data could be converted to ELF note sections, but the whole thing has to work on Windows as well, so I guess they didn't want to depend on ELF. In most projects, you can add this to your Makefile and forget about it: .mli.cmi: ocamlfind ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) \ -c $< -o $@ .ml.cmo: ocamlfind ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) \ -c $< -o $@ .ml.cmx: ocamlfind ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) \ -c $< -o $@ clean: rm -f *.cmi *.cmo *.cmx *.cma *.cmxa
- ableal 9y ago> Bjarne's made the mistake of having C++ rely on C's linker model, so it meant no modules. > Now we can see it as a big mistake, but on those days probably it was one of the reasons why C++'s adoption took off. No mistake, just no choice - the original (1986 or so) C++ cfront compiled C++ to C which it fed to the C compiler and linker chain.
- pjmlp 9y ago> "but on those days probably it was one of the reasons why C++'s adoption took off." It is a mistake with 2017 eyes, because build times are now insupportable. Of course it was the right decision in 1986 when trying to get adoption inside AT&T. Also I have read "Design and Evolution of C++" back when it was published, and know C++ since Turbo C++ 1.0 for MS-DOS, so I grew with the language. Which is also a reason why I still select it as member for my Java, .NET and C++ toolbox trio. However the first ANSI C++ was approved in 1998, and many of us were expecting to get some kind of module support in C++0x.
- Yttrill 9y agoModules would be very hard to make work in C++, there's way too much entanglement at all levels. Of course the rot actually started with the ANSI C committee when it introduced typedef and broke context free parsing. C++ just compounds this kind of problem with template lookup stupidity. Its what you get when languages are designed by people with no understanding of basic computer science.
- JabavuAdams 9y agoI used to be a C++ guy for 20 years, but won't go back unless absolutely necessary. I mean, it's tempting -- there are some cool new language features. I find that the abstractions are leaky, though, so you still have to understand all the hairy edge-cases. The language has gone insane. I'm 40 -- I want to get stuff done before I die, not play clever games to get around my language / system.
- ddalex 9y agoI've given up on C++ 5 years ago, after 10 years of getting paid to develop it. I find out the extra money that come from a C++ job doesn't cover the gray hairs of trying to tame the language so you don't shoot yourself in the foot a dozen times every time you call a method.
- pjmlp 9y agoA bit older here. C++ has been by next loved language after Turbo Pascal, since then I learned and used countless languages, but C++ was always on the "if you can only pick 5" kind of list. Since 2006 I am mostly a Java/.NET languages guy, but still keep C++ on that list. Mostly because I won't use C unless obliged to do so, and all languages intended to be "a better C++" still haven't proved themselves on the type of work we do, thus decreasing our productivity. Because in spite of Swift, Java, .NET and JavaScript, C++ is the best supported option from OS vendors SDKs. I dream of the day I could have an OpenJDK with AOT compilation to native code with support for value types, or a .NET Native that can target any OS instead of UWP apps. Until then C++ it is, but only for those little things requiring low level systems code.
- jchw 9y agoGo is a good example of a language with fast compilation times. Of course, the optimizer needs improvements, but I believe they keep managing to make it faster as they improve the output rather than slower.
- mpweiher 9y agoWasn't that Wirth's rule for Oberon and/or Pascal? Any optimization introduced has to have sufficient cost vs. benefit ratio that it makes the compiler faster compiling itself.
- jchw 9y agoIn Go's case, I think they're simply improving a lot of unrelated aspects of the compiler while adding new optimizations. I like the idea of that rule but there are definitely cases where I would want an optimization that could take a long time during compilation but provide an immense benefit later.
- azeirah 9y agoAh yes, I remember that rule, I think it's incredibly clever. I believe he had another rule, language updates can only /strip/ features, so the core language will always get smaller and smaller. Brilliant
- xg15 9y agoIntuitively, that doesn't seem clever to me. (You're committing yourself to a less efficient, more clumsy language for the benefit of... what exactly?) How does that law improve the language without falling into the trap mentioned elsewhere in this thread? (Optimizing for a pleasant "compile experience" at the cost of everything else)
- foobarchu 9y agoWell, the rule is attributed to Niklaus Wirth, whose credits include Modula, Modula-2, Oberon, Oberon-2, and Oberon-7. The -* languages are extensions of their originals, so it seems his rule only applies within a single edition of the language. They can add new things, because they are new languages. The justification, then, seems to be that if you legitimately need new features, then the language has failed and you should start over anyway. I think Python 3 is sort of an offshoot of this idea, except that many of the new features keep getting backported to 2.7 anyway.
- andrepd 9y agoAre you serious? You want to make a product: a Web browser. What technology are you going to choose? The one that makes your browser fast but gives you more work, or the one that makes your browser slower but makes compilation less of a nuisance to you? It's mind boggling that some would openly say that, hey, who cares about performance that much, these compilation times bother me, the developer. On a browser of all things! Would you be okay with your browser being 2x or 3x slower?
- gizmo 9y agoFalse dilemma. You can have both. It's okay if a fully optimized release mode binary takes a bit longer to compile, but compiling a few million lines of code for a debug build shouldn't take more than a second or two. Also consider the leverage factor. Improvements to the compiler benefit all users of the programming language, so it's worthwhile to invest in high quality compilers.
- striking 9y agoIn what language can we have both? Yes, we can use caching compilers (https://wiki.archlinux.org/index.php/ccache https://wiki.archlinux.org/index.php/ccache) to speed up builds with few changes. We can lower optimization levels (although that barely gives you an increase in compile speed compared to the runtime speed you lose and the fact that it makes your program do slightly different things). There's no slider from "pessimum" to "optimum". You need to do wildly different things to optimize past this point for compile speed. Erlang hot-reload and at-runtime-code-gen from other langs come to mind. But that will almost definitely slow down your program because of the new infrastructure your code has to deal with. I have observed that there can be a nice balance with Java and the auto-reloading tools that are available for it. But I am unaware of their limitations and how a web browser might trigger those limitations.
- p0nce 9y ago> In what language can we have both? Have you actively tried to find one?
- qznc 9y agoI'm not sure if the approach of Lisp and Jai (and also D) is the best one. They all have practically arbitrary code execution at compile time, so they can be arbitrarily slow to compile. In C++ template-programming is so hard that few people do it, but in those languages it is just as easy as normal code. With mainstream languages, code generation is done by the build system which can avoid repetition. Caching generated code feels like a good idea to me. Doing it with compile time execution is (unnecessarily?) hard.
- Kapura 9y agoIt seems that, in Jai, arbitrary code execution at compile time is exactly the point. The build file itself is just another Jai program. It's easy to wring one's hands about a novice programmer making the computer do unnecessary work, but Blow's philosophy seems to be to trust the programmer to understand the code they're writing. And if they don't, they should probably be using another language.
- lispm 9y agoCompiling Common Lisp code isn't too slow. There are some quick compilers like Clozure CL. What slows some Common Lisp native code compilers down is more advanced optimization: type inference, type propagation etc, lots of optimization rules, style checking, code inlining, etc.
- mtanski 9y agoThis whole sub-thread tangent-ed into C++ is bad because it's compilation causes this problem. Problems with C++ builds are well understood... This specific issue prob impact other batch workloads with lots of small tasks (processes). There's no reason this should be happening on a 24 core machine.