r/programming • u/eatonphil • May 10 '20
Make LLVM fast again
https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html11
u/matthieum May 11 '20
For every tested commit, the programs are compiled in three different configurations: O3, ReleaseThinLTO and ReleaseLTO-g. All of these use -O3 in three different LTO configurations (none, thin and fat), with the last one also enabling debuginfo generation.
If I may... I'd really like to see Debug added to that list.
Personally, whether in C++ or Rust, the majority of the time I spend waiting for a compilation to complete is when developing locally, and this means -O0 or potentially -O1, and certainly no LTO.
Indeed, I don't mind a 10x increase for the build-time of Release artifacts if that means a 10% increase in performance. I'm rarely, if ever, bottlenecked by them.
On the other hand, a 10% increase for the build-time of Debug artifacts is horrendous. I'm already waiting too long -- and getting distracted.
17
u/ExeusV May 11 '20
Sorry for my noob question, but aren't there modes like
--debug
--release
where first tries to compile as fast as it can?
43
u/jcelerier May 11 '20
Generation of debug info has a cost too, for large projects it can be tens of gigabytes of debug info... that's not free
12
u/S4x0Ph0ny May 11 '20
Well from my very biased experience using mostly just rust I wouldn't call the debug mode very fast to begin with. And that doesn't mean buildtime on release mode doesn't matter. Performance always matters, but it's a trade-off.
1
u/thisisjustascreename May 11 '20
-O0 exists and tells the compiler not to optimize, but there's no guarantee that it compiles faster.
0
17
u/kankyo May 11 '20
This is truly doing gods work. More power to this gentleman right here.
11
May 11 '20
[removed] — view removed comment
2
u/kankyo May 11 '20
Making something better is good.... but maybe we should have let PHP go silently into the night.
64
u/quicknir May 11 '20
I have two issues with the article.
While that may be true, I don’t think it is a desirable trend: For the most part, optimization is already “good enough”, and additional optimizations have the unfortunate trend to trade large compile-time increases for very minor (and/or very rare) improvements to run-time performance.
I just kind of think the author is misguided here. If llvm is looking to be competitive as a backend for production C and C++, there's just really no such thing as "good enough". A lot of the use cases of C and C++ always want better performance. For good enough performance, there's just about every other language and framework. If you've tied your wagon to something so intertwined with the C++ ecosystem, you should go into it with this knowledge.
The other issue is that I didn't see discussion of debug build times. I could have missed it though. At any rate, if debug build times aren't getting worse, then this more or less shows that there's no collateral costs to adding optimizations. It's building slower because more time is spent optimizing and no other reason. At that point, what's needed is not really better build times at max optimization, but just more and easier to use options (e.g. -O1.5) to disable less efficient optimizations.
58
u/ssylvan May 11 '20
I feel like you're focusing too much on a throwaway statement that isn't super important for the main point of the article.
It's not really about legitimate tradeoffs between compile time and runtime. Rather, since compile time wasn't tracked there really wasn't even easily available way to even do the tradeoff in the first place - people were just unaware that they did something that made compile time worse (and likely could've at least mitigated it to some extent if they had been aware). How many of these regressions could've been avoided with zero impact on runtime performance? We don't know. Maybe most of them?
25
u/AlexReinkingYale May 11 '20 edited May 11 '20
I just kind of think the author is misguided here. If llvm is looking to be competitive as a backend for production C and C++, there's just really no such thing as "good enough". A lot of the use cases of C and C++ always want better performance. For good enough performance, there's just about every other language and framework. If you've tied your wagon to something so intertwined with the C++ ecosystem, you should go into it with this knowledge.
This might be a bit controversial, but as a high-performance computing researcher and compiler constructor myself, I agree with the author for the most part. If you need absolute maximum performance, you either shouldn't expect your compiler to give it to you or you shouldn't be writing in C/C++.
Here's what good enough means: the compiler's output won't bottleneck your optimization efforts. And this is mostly true. No matter what sort of application you're writing, the quality of LLVM's output is so high that the most important optimizations come from large-scale reorganizations of computation and resource loading, full stop.
Discovering these reorganizations in a setting as unconstrained as C/C++ just isn't possible. The set of legal optimization steps depends on the particulars of the program that a general-purpose compiler isn't able to reason about. Even if it could, the space is so large that there's no way to explore it. Even if it could do that, the fastest program might not even be reachable from a series of legal steps. Eventually you'll need to assume your compiler can solve the halting problem.
So the alternatives are to either painstakingly write assembly, or encode the particulars of the problem you're trying to solve in a domain-specific language. In a well-designed DSL, the space of allowable optimizations is much more targeted and you can push your performance much farther than you can in C/C++ alone.
13
May 11 '20 edited May 11 '20
A lot of the use cases of C and C++ always want better performance.
If you only want the best possible performance, then go ahead and use a super-optimizing compiler that takes days or weeks to compile simple snippets of Hello World! code.
If waiting one full day for Hello World to compile isn't acceptable to you, then you don't want the best possible performance, but some trade-off between good-enough performance and good-enough compile-times. If these aren't "good-enough" then you can't use them.
2
u/Full-Spectral May 11 '20
Yeh, it often comes down to making the many suffer for the needs of the few in C++ world. I've whined about this a lot. Make the common stuff far simpler for the creator to maintain bug free and far easier for the user to use, and leave the specialized needs to specialized tools. I mean it's not like C isn't till there if they want some super-optimized low level algorithm here and there as well, or even assembler.
9
u/Dave3of5 May 11 '20
Slow compile times are a real bugbear of mine. If it's gradually getting slower I can see real frustration ahead.
4
u/xmsxms May 11 '20
You could always turn a bunch of optimisations off to speed up compilation.
5
u/SkoomaDentist May 11 '20
This would be the right answer in a world where the common build tools allowed you to easier specify different compiler flags for different parts of the source code. For most programs you get most of the speedup from a relatively small number of components while everything else could be compiled with -O1 for only minor speed difference.
1
u/xmsxms May 11 '20
You can put your critical code in a different object file and compile that with higher optimisation levels.
1
u/SkoomaDentist May 11 '20
Yes, but note the keyword "easier". That means "one or two lines extra", not "let's rewrite the whole build script".
1
u/flukus May 11 '20
Which tools would force you to rewrite the build script? In make it's just a matter of adding a more specific target with the files you want.
2
u/evaned May 11 '20
And what do you do when even no-optimization builds are frustratingly slow, like they sometimes are with C++, Rust, and other slow-to-compile languages?
14
u/free_chalupas May 11 '20
Please no more "make X Y again" headlines
54
29
5
u/MorrisonLevi May 11 '20
The author is not US-based, FYI. Does that change your opinion at all? IMO it should: what some political figure somewhere in the world said should have relatively little bearing on a technical headline for the entire world.
2
u/JoelFolksy May 12 '20 edited May 12 '20
what some political figure somewhere in the world said should have relatively little bearing on a technical headline for the entire world
Agreed, that's why I'm naming my next technical article "Heil Rust: the Final Solution for Undefined Behavior."
2
u/free_chalupas May 11 '20
I am 100% positive that they understand exactly what the headline is referencing. I do however sympathize that they might not understand the full impact of that slogan the same way an American writer would.
12
u/Y_Less May 11 '20
I can't speak for the author, but I'm not from the US and had no idea it even could be referencing something until I saw this comment chain.
Thing was fast
Thing is no longer fast
Returning that speed requires effort
Let's do that
Summarised: Let's make thing fast again.
The fact that it sounds vaguely like some comment made by a guy in one country shouldn't matter to using a perfectly valid grammatical structure globally (regardless of how self-important that one country might think itself to be globally).
7
u/invisi1407 May 11 '20
From comments on the blog:
Could we not use "make * great again" as some kind of joke? It's the slogan of a deeply racist, sexist and authoritarian man. To a lot of people, it's not funny, it's a reminder that they are under threat.
It's bullshit. Anyone can use any headline they want; doesn't imply anything.
Let's not allow Trump et. al. to claim a certain sentence as being synonymous with his politics and personality. It wasn't even him who used it first; Reagan did in 1980.
Let's not appropriate "Make X Great Again!" like the Nazis did the Swastika, a symbol of peace.
11
u/free_chalupas May 11 '20
I'm not particularly sad about losing an inherently reactionary political slogan. Even accepting your premise, it doesn't seem too much to ask people to avoid using it while trump is still in office and the association is unavoidable.
8
u/invisi1407 May 11 '20
Trump wasn't even the first one to use it; Reagan was.
I do agree that it carries with it an implication of Trump and his policies, but personally, I can easily abstract away from that and apply it to other things without thinking "Trump!" ever time.
How else are you going to describe the act of literally making something good/great again, that once was but isn't anymore?
2
u/JoelFolksy May 12 '20
How else are you going to describe the act of literally making something good/great again, that once was but isn't anymore?
Well, for example, he could have titled the article "Let's make LLVM fast again." But I don't blame him for going for the reference - I probably would have done it, too.
4
u/free_chalupas May 11 '20
How else are you going to describe the act of literally making something good/great again, that once was but isn't anymore?
Not sure about, but I don't find myself frequently needing to do this. I think I could figure it out.
11
u/invisi1407 May 11 '20
I've seen it used quite a few times online for blogs and Reddit posts where it was appropriate and I, as a non-native speaker, wouldn't be able to come up with something better.
Why spend extra time and energy looking for an alternative, when the first that comes to mind works great?
4
u/free_chalupas May 11 '20
It's evocative of a political campaign that's been a source of hate and misery for many people throughout it's short history. I'm sympathetic to non English speakers who might repeat it without understanding how it can be interpreted, but if you're creating media intended for mass consumption and you understand why this is an issue I think you should put in the effort to avoid using an insensitive headline.
7
u/Y_Less May 11 '20 edited May 11 '20
You missed an important point:
In one country
Things on the internet are generally made for the whole world. You can't dictate that the entire planet stop using a perfectly valid grammatical construct just because a guy in your country also used it.
And I am a native speaker, just not from the US. Why should I have to change my birth language?
1
u/free_chalupas May 11 '20
If someone told me that a phrase I was using in my second language was considered offensive in their country, and their country was a major consumer of media I was creating in my second language, I would 100% listen to them. I'm not sure why this is hard when the second language is English and the county is the USA.
6
u/Y_Less May 11 '20 edited May 11 '20
That may be true if something was specifically targeted at your country, but this is a generic, global, programming article. Yet you're trying to impose your own culture on it. You're saying that because it is offensive to you in your country, no-one anywhere in the world can use it, regardless of connotations (or lack thereof) elsewhere.
Or are you saying it only applies specifically to second language speakers, so native speakers like me are fine to keep using it in generic articles nothing whatsoever to do with one foreign country's politics?
Edit: Not even the same phrase as the one you don't like, but something only vaguely similar, which is even worse.
→ More replies (0)2
u/JasTHook May 12 '20
You've just described every political campaign ever, from someone's point of view.
1
u/free_chalupas May 12 '20
It is true that I did not come prepared to respond to absolute moral relativism. You have got me there.
2
u/JasTHook May 12 '20
well of course if you think that you are always right and have the only valid point of view... that explains your entire performance on this post.
It makes Trump look good and tolerant in contrast.
→ More replies (0)5
u/moi2388 May 11 '20
Why the heck should you not write insensitive headlines? Who determines what is or isn’t insensitive? Whatever headline you write, a subset of people will always be offended by it.
How about we let people write whatever they want, and we all try to get a little bit less offended by a sequence of words?
-1
u/s73v3r May 11 '20
Why the heck should you not write insensitive headlines
The same reason normal people wouldn't say insensitive stuff to a person's face: It's unnecessarily mean, and really does not serve a purpose outside of being mean.
3
u/moi2388 May 11 '20
My point is you don’t know what might or might not be insensitive to someone. For example, redacting speech solely based on someone’s feelings offends me, which makes your comments insensitive to my feelings. Should you redact them?
→ More replies (0)0
u/free_chalupas May 11 '20
Perhaps instead of fantasizing about an imaginary world where no one is ever offended by things they associate with traumatic experiences, we could simply avoid extremely recognizable phrases that evoke fascist politicians
3
1
0
0
May 11 '20
[deleted]
-4
u/free_chalupas May 11 '20
Perhaps the real mistake was using a politically charged headline and not expecting it to distract from the content of the article
-40
u/Phrygue May 11 '20
I don't know much about modern compilation bottlenecks, but I suspect, as always, it's the file access that's the problem, not the code. So how about consolidating the files and forget about tweaking 0.2 percent out of your inliner analyzer? Stop thinking in terms of how C/C++ lay out your files. If you can't one-pass it, you should be hating it intensely, like a box of punch cards spilled on the floor, because WTF decade is this??
57
22
u/flukus May 11 '20
but I suspect, as always, it's the file access that's the problem, not the code
It's basically never about file access, especially when the files are already cached in memory like they're likely to be after initial compilation. At least on Linux.
3
-43
u/fijt May 11 '20
It is easy when you *dare* to do things that are not the ordinary, such as creating a new C version that although it isn't compatible it's also very fast to compile and safe. This takes guts and I don't think that you guys have any. Sorry.
7
u/kankyo May 11 '20
Isn't that kind of rust?
-14
u/fijt May 11 '20
The downside of Rust is that the language is complicated compared with a language such as v-lang.io or Go. There you can find simplicity. And simplicity is a benefit that is so hard to get but yet so hard to deal with on a daily basis. So my proposal would have been the language Go but then based onto the compactness of C. Rust is not that language.
15
11
May 11 '20
Vlang is little more than a regex powered transpiler for C. The author has no idea what he's doing.
2
u/not-enough-failures May 12 '20
I would appreciate their effort and root for them if they didn't claim it's ready for action so much.
They show 3992746392 demos of complicated things, half of them don't compile, the other half crash at runtime.
7
u/evilgwyn May 11 '20
How could you say something that is simultaneously so controversial and yet so brave
-8
2
u/flukus May 11 '20
C is very fast to compile. Is there a language in it's class (no runtime, systems language) that compiles faster? Pascal's about all I can think of.
2
u/OneWingedShark May 11 '20
C is very fast to compile.
Meh, there are things that make it harder to compile than it should be.
Is there a language in it's class (no runtime, systems language) that compiles faster? Pascal's about all I can think of.
C has a runtime, that's one of the things that a lot of people claim you need for systems-programming, "because everyone uses C to implement language/system X".
Forth is much more in-line what you're thinking. Maybe BLISS.
1
u/fijt May 11 '20
C has a couple of issues about compiling. PASCAL did have it right with the ordering, and the same counts for Go.
31
u/jl2352 May 11 '20
I remember years ago reading about some C++ developers who use GCC using LLVM instead for local development, because it was way faster and gave better error mesages. Then continue to use GCC for production builds.
Today in the Rust world there is discussion on using Crane Lift for development builds, and LLVM for production builds. The history of Rust's slow compile times is heavily entangled by LLVM. To the point that LLVM is basically the main issue now.
It's crazy how the tables have turned from LLVM being known for being fast, to being known for being slow.