News for hackers. Stuff that matters.
Re:New SSA Back End for the Go Compiler (2015) by geodel on Saturday April 02, 2016 @12:11PM (#11412028)
You say it is arrogant but is it untrue? Rust uses LLVM backend and it takes order of magnitude longer to compile compare to Go.
Re:New SSA Back End for the Go Compiler (2015) by pcwalton on Saturday April 02, 2016 @12:25PM (#11412090)
The reasons why Rust is slower to compile are basically (a) typechecking takes longer; (b) LLVM does way way more optimization than Go's backend does. (b) applies even at -O0 because it has to go through LLVM IR to SelectionDAG to MachineInstrs, while Go 6g/8g pre-SSA can just go from AST to MachineInstrs. (We can't use FastISel at the moment because FastISel has no support for unwinding, among other minor reasons.)

If Go adds all the optimizations that LLVM does, then I have no reason to believe that it won't end up just as slow as LLVM.

There's active work to fix both (a) and (b): for (a) there are ideas for an O(1) unifier in typechecking, and for (b) we're working on MIR (which is now able to self-host) to do higher-level optimizations on a language-specific IR to avoid punting them to LLVM, where it may take more work to figure out. (For instance, we can do inlining on polymorphic functions, reducing the time complexity from O(number of instantiations) to O(1).) But the biggest wins will come from incremental compilation, which there's been a ton of progress on lately and might just fix the compilation time issues once and for all in practice.

Re:New SSA Back End for the Go Compiler (2015) by dilap on Saturday April 02, 2016 @01:18PM (#11412299)
Well, Go still won't be paying for (a) right?

So my non-expert, just-a-normal-programmer feeling is something still doesn't add up -- I feel like you could compile C++ with optimizations off, and it would still lose at compile time, and really lose at runtime, to Go.

So somehow Go is compiling quickly and running fastishly.

So "it doesn't do optimization is why it compiles fast" is confusing.

Is the story that Go, as a simpler language, is able to compile to decently fast code w/ fewer compiler optimizations?

I'm thinking along the lines of C++ zero-runtime-overhead template stuff is very-large-overhead w/o optimizations.

I've only played a tiny bit with Rust, and it was a long time ago, but my experience is there was no "fast compile time, decent runtime" configuration available. Naturally, that's a really good configuration to have accessible if possible!

Re:New SSA Back End for the Go Compiler (2015) by pcwalton on Saturday April 02, 2016 @01:40PM (#11412399)
Yes, C++ is dependent on optimizations. It's not that C++ is a complex language and that Go is a simple language, though--in fact, due to GC metadata Go is on the whole probably more complex than C++ once you get to the LLVM IR level. C++ (like Rust) is runtimeless and has no data structures built-in, so every time you use a hash table (for example) the implementation of the hash table is compiled alongside your code. In Go, hash table operations compile to opaque runtime calls (I believe), to a runtime that is always optimized. This is faster for compile time, but it's slower for runtime, frequently much slower because containers benefit heavily from IPO. (For instance, SROA and inlining are a powerful combination, allowing for the length of a short-lived array to be promoted to an SSA register and thereby allowing vectorization, etc.)

Go's compiler is not competitive with a mature backend like GCC or LLVM. It's "fastish" for the niche it's in, but there's no substitute for the nonstop 10+ years of optimization work that has gone into the flagship open source compilers. I don't see LICM in Go's source at all, for instance, and that's a really basic one.

> I've only played a tiny bit with Rust, and it was a long time ago, but my experience is there was no "fast compile time, decent runtime" configuration available. Naturally, that's a really good configuration to have accessible if possible!

There is -O1, but it has basically the same compile time as -O2, so it's not used in practice.

Re:New SSA Back End for the Go Compiler (2015) by dilap on Monday April 04, 2016 @10:51PM (#11427464)
I appreciate the detailed replies!

I guess complex is an ambiguous word. Let's just agree that template-heavy "modern" C++ needs more optimizations turned on to get decent performance. So more optimizations => longer compiler times. (Not to even mention all of the parsing the headers multiple times, plus generating multiple versions of the code for all of the various type specializations!)

From the other replies, I feel like there's more to it than just optimizations though -- but as just a compiler-user, not a compiler-writer, I'm out of my depth and just reading tea leaves. :)

Reading those tea leaves, I'll be sadly surprised if the Go compiler ends up slow and happily surprised if a C++ compiler ever ends up as fast.

(I don't know enough about Rust to make any predictions. ;)

(PS. No disagreement that C++ has a higher performance ceiling than Go; of course hand-rolled asm still goes higher than that (ever tried running x264 w/o the assembly bits? it's painfully slow).)

Re:New SSA Back End for the Go Compiler (2015) by sievebrain on Saturday April 02, 2016 @02:14PM (#11412556)
Is the story that Go, as a simpler language, is able to compile to decently fast code w/ fewer compiler optimizations?

Sort of. But it's also that you're making bad comparisons. C++ has an include based compilation model and heavy reliance on template specialisation that means it'll never be fast.

What you should instead be comparing it to is Java, which is also a simple language, only slightly more complex than Go. However, that comparison is rarely made, because it'd show that compiling fast is not so special a trick ... Java also compiles extremely fast at every level, that's why it's possible to use a JIT compiler with it at all.

Given that "compiles fast" is Go's number one claim to fame, the reluctance to compare to the most popular compiled language is the elephant in the room.

Re:New SSA Back End for the Go Compiler (2015) by nickpsecurity on Saturday April 02, 2016 @02:54PM (#11412757)
What did it take to fo that in Java? When I tried Java on a Pent3, it took a few seconds to compile. The BASIC and Wirth languages could do tens of thousands of lines a second on same machine. Then they consistently ran faster than Java.

The only elephant in the room is the bloated, insecure platform sitting on many servers. Competition showed one could do much more with less CPU, memory, or money invested in tooling itself.

Re:New SSA Back End for the Go Compiler (2015) by pcwalton on Saturday April 02, 2016 @03:07PM (#11412831)
HotSpot's sea of nodes IR is far beyond anything Turbo Pascal did in terms of balancing compile time and runtime. It's not even comparable.

Few people are as consistently right in their field as Cliff Click is with JITs and language runtimes.

Re:New SSA Back End for the Go Compiler (2015) by nickpsecurity on Saturday April 02, 2016 @03:12PM (#11412862)
Dude is brillaint and did great work. Yet, the Oberons and Pascals compiled so fast my finger was barely off the key when they were done. Even the C/C++ editors werent that fast for Java. Allowed rapid iteration while maintaining mental flow. When done, you turn all the options on with that or a slower compiler to get fastest, production version. This has been true going back to the old, Ceres workstations where commenters here that used them reported instant compiles on CPU's with tens of MHz.
Re:New SSA Back End for the Go Compiler (2015) by pcwalton on Saturday April 02, 2016 @03:15PM (#11412873)
Yes, and they didn't do any optimization. That's not particularly interesting; TCC is there if you want it.
Re:New SSA Back End for the Go Compiler (2015) by nickpsecurity on Saturday April 02, 2016 @03:22PM (#11412913)
Barely any. Which leads us to differentiate between iterative and release requirements. Language like Go will kill on the former with Wirth-style compilees. A LLVM extension might have been better for latter. That was my recommendation a while back. Even still, the language is simple enough it should compile faster. Should != will of course.
Re:New SSA Back End for the Go Compiler (2015) by sievebrain on Saturday April 02, 2016 @04:45PM (#11413340)
On a Pentium 3? Don't you think such a comparison might be out of date? Java has changed a lot since those days.

Yes, Pascal/Delphi also compiles very fast, it's true, but they also forbid circular dependencies and impose other restrictions that caused a lot of developer pain.

Re:New SSA Back End for the Go Compiler (2015) by nickpsecurity on Saturday April 02, 2016 @09:07PM (#11414421)
Let's say we port it from P3 to multi-core, 2GHz x86. We want to know if prior performance was relevant as a predictor. As in, will difference choices made on old platform apply to new? Here's a few examples to illustrate:

1. Interpreted vs compiled language.

2. Simple, Oberon-like type checks vs Rust or Ada.

3. Several pages of BNF in grammar vs 1 or 2.

4. Designed for abstract, heap machine or just above real, stack machine?

5. Number of steps needed between source and efficient exdcution.

6. Number of times you perform those steps (eg AOT vs JIT).

7. Cache-awareness of design.

These are a few key differences between Java and Wirth-style languages then. They made compiles rapid on P3. Updating to multicore or 64-bit would be trivial given each update at ETH was a few undergrads work for 6mo-2yr. So, do lessons learned that those attributes Wirth-style greatly aid performance of compilers and runtime still apply today?

I think so given what Go accomplished in its time and resources. Other languages too with design decisions that proved out over time. It took truly epic work and investment to get Java to its current situation.

I havent heard people say Pascal caused them lots of pain aside from functional crowd or some wanting a few C++ features. What specifics bothered you? And why did you need circular dependencies?

Re:New SSA Back End for the Go Compiler (2015) by dgacmu on Saturday April 02, 2016 @02:18PM (#11412582)
Go wins at compile time in part because its import system avoids a ton of the redundant work that C++ includes bring with them. So, yes, go would compile lot faster than C+l -O0, but that's a language difference, not a compiler difference.
Re:New SSA Back End for the Go Compiler (2015) by nickpsecurity on Saturday April 02, 2016 @02:48PM (#11412730)
Wait, wait, did you say incremental compilation? As in, instantaneous compiles of individual functions like LISP or my old 4GL? Or cached, one-module-at-a-time compilation like most 3GL tools? Really hoping it's the former.
Re:New SSA Back End for the Go Compiler (2015) by pcwalton on Saturday April 02, 2016 @02:51PM (#11412743)
It's recompiling only the functions that have changed. The code to build and persist the dependency graph has already landed.

https://github.com/rust-lang/rfcs/blob/master/text/1298-incr...

Re:New SSA Back End for the Go Compiler (2015) by nickpsecurity on Saturday April 02, 2016 @03:08PM (#11412833)
HELL YES! You people are embodying The Right Thing approach yet again! I just received more motivation to learn this language given it might soon be first mainstream one to equal LISP in a key way. Aside from the mainstream LISP in Java land of course....

Now, the only thing left is a real-time interpreter with live code updates. I recall the LISP box could do instant changes interpreted for exploratory stuff on running image. Solidify that super fast with per-function, typed compiles. Plus do whole program compiles if you had to. So yall getting close but what's odds of those other features happening?

Note: Live, interpreted image with save the world also makes it easier to debug stuff locslly and remotely. Send devs the whole, running state.

Re:New SSA Back End for the Go Compiler (2015) by killercup on Tuesday April 05, 2016 @10:49AM (#11430789)
Some people have worked on a Rust REPL, but it wasn't really useable last time I checked. Part of the motivation to develop this was the possibility to use LLVM as a JIT, which is pretty nice.

Personally, I would love to see this as part of an IDE that can execute _parts_ of a Rust file with various inputs to quickly see if a function behaves as expected (this could also be easily converted into test cases.)

Re:New SSA Back End for the Go Compiler (2015) by nickpsecurity on Tuesday April 05, 2016 @09:32PM (#11435966)
That's the idea. They're great for exploratory programming. In LISP, safety was optional. This was actually OK... would be in Rust... if your goal in that mode was to understand requirements, algorithm, solution space, etc. Get an idea of how you might handle it. Then, turn safety back on, try to get a solution going. When it works, compile that module. Future tweaks do incremental compilation.

Rapid development cycle doing features this way.

Re:New SSA Back End for the Go Compiler (2015) by geodel on Saturday April 02, 2016 @03:16PM (#11412879)
1)-O0 code from LLVM will run faster than Go code?

2) Since we are talking order of magnitude more time, Will optimized code from LLVM will be order of magnitude faster than Go?

Re:New SSA Back End for the Go Compiler (2015) by pcwalton on Saturday April 02, 2016 @03:22PM (#11412912)
> 1)-O0 code from LLVM will run faster than Go code?

It depends on the language. It would be interesting to see -O0 LLVM vs. 6g/8g on Go code.

> 2) Since we are talking order of magnitude more time, Will optimized code from LLVM will be order of magnitude faster than Go?

Maybe? If you vectorize it sure could be. But I don't see why it's relevant. Who cares if your final release builds for your browser are 10x slower if you're shipping them to 100 million users and they get a 3x speedup?

Re:New SSA Back End for the Go Compiler (2015) by geodel on Saturday April 02, 2016 @03:53PM (#11413075)
True for browser.

I guess you will agree business applications are far more commonly written than browser engines. For my business application in Java it is neither super fast to compile (~20sec from ant script). Quite slow to start due to VM startup time, and ok performance. I would really like if compile times are much faster.

Re:New SSA Back End for the Go Compiler (2015) by DannyBee on Saturday April 02, 2016 @12:19PM (#11412076)
It is untrue, given the same amount of work put into both (IE if they had spent their time doing llvm instead of their own ssa backend).

Remember the SSA backend of Go was slower than the normal go compiler for the vast majority of it's life as well.

In any case, people like to build shiny new things they think they can do better at, instead of fixing things that are, in actuality, probably better for what they want but need a little work.

The truth is that there is no magic in building good compilers, so it's not like anyone comes along, waves a wand, and produces a compiler that is X times faster or better than anyone else's.

I can think of a lot of good reasons to write their compiler in go, and not use LLVM. Technical reasons are ... not any of them :)

Re:New SSA Back End for the Go Compiler (2015) by geodel on Saturday April 02, 2016 @04:39PM (#11413306)
> Remember the SSA backend of Go was slower than the normal go compiler for the vast majority of it's life as well.

Go 1.7 in August will be first release with SSA backend. So I do not understand what is that vast majority of life besides development phase of 1 year or so.

> In any case, people like to build shiny new things they think they can do better at, instead of fixing things that are, in actuality, probably better for what they want but need a little work.

I agree with that. It could just be a comment on our society.

> I can think of a lot of good reasons to write their compiler in go, and not use LLVM. Technical reasons are ... not any of them :)

I think goroutine and segmented stacks support was mentioned as technical reason.