text
stringlengths
0
1.82k
**Erik St. Martin:** \[08:02\] It was a while ago that I saw the video. I didn't get to watch the talk while I was there, but I remember vaguely that there was no assembly stage in the compile process.
**Keith Randall:** Right, we go directly from the compiler output... It generates something called the obj library; it generates basically one structure for every assembly instruction that tells you what the register inputs and the register outputs are. And then actual instruction selection, like encoding the bytes of ...
**Erik St. Martin:** Oh yeah, so it doesn't... Because in a typical approach the compiler would emit assembly instructions, and then those would then get turned into the actual machine code by the assembler. So you're saying that that obj library converts the IR directly into the machine instructions by using kind of i...
**Keith Randall:** Exactly, yeah. So our assembler is really just the parser. It doesn't assemble in that sense. The obj library, which is part of the linker (sort of) is the thing that actually does instruction selection from the internal representation.
**Erik St. Martin:** Interesting. I need to start playing with compiler internals. \[laughter\] It's a little below where I usually work, but it's really interesting. So looking at the changes -- and I know that a lot of the work that you guys have been doing has been making it easier to port to new architectures on th...
**Keith Randall:** The new SSA backend is very easy to port. There's just a machine description file that has all the opcodes you wanna use, and a bunch of read/write rules that tell you how to get from machine independent IR to a machine-dependent IR.
As far as the compiler itself, whether you can embed a compiler in some other program, it's not directly reusable, although it's certainly more reusable than the old compiler, and that's the direction we're heading - to get to the point where we could - if we wanted to - make the compiler a library.
**Erik St. Martin:** I don't think I have a direct use case for that, but it's just interesting to kind of see these different languages build on top of things that other languages have done, and kind of leverage that stuff where there's shared resources, so if somebody wanted to make their own spinoff of Go that has s...
**Keith Randall:** Yeah, that would be nice.
**Bill Kennedy:** I was curious, we constantly talk about how fast the compiler is and how we're trying to bring it back down to that when it was written in C, but optimization's also really important, so how do you guys strike a balance about how much optimization the compilers do, as opposed to how much time that wou...
**Keith Randall:** It's a good question. There is a tradeoff there, and at some point we're gonna have to say no - and we have said no - to optimizations that just would take too long otherwise... Like alias analysis; we haven't done any yet, and we're sort of scared to go down that route because it can be very expensi...
\[11:42\] The original goal of the SSA compiler was we wanna make the compiler generate code that's better enough that the compiler gets no slower because we compile the compiler with the compiler. So we sort of wanna buy back all the extra time we're spending by making the compiler faster, and we didn't quite get ther...
**Erik St. Martin:** I always love how meta that is. \[laughter\]
**Keith Randall:** It is very meta. It's hard to describe.
**Bill Kennedy:** Are there optimizations that - I guess once all this SSA stuff is done - you'd like to see maybe going forward?
**Keith Randall:** Sure. We got some of the major ones, like common self-expression, which are very important. There are ones that we could do that sort of are more domain specific. We could certainly improve our generation of floating-point code, for example. We could do a better job at bounds check elimination. We co...
There's things like that, but at some point we're gonna reach diminishing returns; it's not worth the extra effort of coding, it's not worth the extra runtime with the compiler to do those sorts of things. Then at some point we're gonna have to declare that we're done, or at least we're done unless someone comes up wit...
**Erik St. Martin:** There's always "more better."
**Keith Randall:** That's true, yeah.
**Erik St. Martin:** I think there's the fear that there's an end, but it's just like any goal in life - by the time you get anywhere close, you've drawn the line out further, right? There'll be something else that comes up and you're like, "We need to do that!"
**Keith Randall:** That's true. And there's always people filing bugs, saying "Hey, my program is not as fast as I think it should be. You guys should fix this." I have a stack of them that I have to look at. So yeah, there will always be complaints; it's just a question of, you know, there's limited manpower and there...
**Erik St. Martin:** Yeah, I guess that's the tradeoff, too. It's the same thing with the language. The whole thought process behind the language is how do we provide everybody what they need without providing them too much, and it's the same thing with the compiler. How do you do everything you need to do but without ...
**Keith Randall:** Right.
**Erik St. Martin:** Every time I have to compile a C or C++ app I wanna email all of you and thank you. \[laughter\] You forget, and then there's one day you have to work on something and build it and you're like, "Oh, this is so bad."
**Keith Randall:** Yeah, I had to download LLVM at one point and build it and it took like two hours. Like, how is this possible? I mean, I'm sure there's some incremental thing which you could do better if you're a developer, but from scratch it took like two hours to build.
**Erik St. Martin:** I remember doing this on processors less than a gigahertz. I remember upgrading GNOME or KDE back in the day, you'd let it run over night.
**Keith Randall:** Yeah, I don't wanna go back to those days.
**Erik St. Martin:** And the 56k modems... I don't wanna go back.
**Keith Randall:** Our house at home just got upgraded from a 2 MBits connection to a 6MBits connection, as we live in the boonies and we're too far from the central office for anything good. But just the jump from 2 MBits to 6 MBits has been awesome.
**Erik St. Martin:** It's like life-changing.
**Keith Randall:** It is. Now more than one person can watch a video at a time in our house, so we're not hitting each other over the head whenever anyone else is doing anything that's ruining our videos.
**Erik St. Martin:** It's not fighting over "Who can use the bathroom to brush their teeth first", it's "Who gets to watch their movie."
**Keith Randall:** Yeah, exactly.
**Erik St. Martin:** Like, "You watch cable, I get Netflix today!" So what's next for the compiler, what's exciting? What do you have planned for the next couple releases?
**Keith Randall:** \[15:58\] Let's see... One of the big things that's coming - or will, if it works out - is we're gonna change the calling convention. Right now when you call a function everything gets passed on the stack in memory, and everything gets returned on the stack. That's pretty inefficient, but it makes th...
It's sort of a big project. It's not terribly hard coding-wise to get the compiler to generate that code, but it has a lot of implications for the runtime and it has a lot of implications for... Like, everyone who's ever written assembly would have to change their assembly, so we're sort of looking at how we roll such ...
**Erik St. Martin:** How much assembly would you say exists in the Go standard library and runtime?
**Keith Randall:** The standard library might have 10,000 lines of assembly...
**Erik St. Martin:** Wow.
**Keith Randall:** It's not huge, but there's a lot of stuff for all the... BigInt has a lot of assembly, all of crypto stuff there's a lot of assembly, and then you could put assembly in your Go project, so there's probably all kinds of stuff on GitHub that we don't even know about that has assembly. That's the stuff ...
We're currently thinking about how we might roll such a thing out if it ends up working out.
**Erik St. Martin:** Yeah, that almost feels like it's gonna have to be some sort of phased approach where there's like at least a release or two to kind of give people time to convert.
**Keith Randall:** Yeah, and we were thinking about... You know, the current assembly, when we switch to a new calling convention, we can then generate stubs for all the old calling convention things, and then you can sort of opt in to get the new calling convention and we'll remove the stub as you change your code. So...
**Erik St. Martin:** Right.
**Bill Kennedy:** Do you work on any of the escape analysis stuff for the compiler too?
**Keith Randall:** I've touched escape analysis, yeah. I am not a major contributor to it. David Chase did a lot of the most recent stuff.
**Bill Kennedy:** Okay. There is a document that Dmitry put out a little over a year ago on some of the escape analysis flaws and I was curious how much of this has been worked on over that year, and if there's any update to what's left.
**Keith Randall:** I don't know, that's a good question. I know that it's another one of those never-ending rat holes you can go down, trying to get every last case that people care about. I don't think anyone's been working on it seriously for the past year. Maybe fixing obvious bugs and things, but there's been no co...
**Erik St. Martin:** I have a question for you. We actually have a C++ app that requires real-time thread support. Over this past week we were kind of joking about, "Would that be something we could ever rewrite in Go?" Basically it takes MPTS streams - multiplexes, multiple MPEG video streams together, and to keep the...
**Keith Randall:** Yeah, it's a good question. I think it should just work. If you take a goroutine, lock it to a thread and tell the OS "Give that thread high priority", that should just work. You'll get pauses when GC starts and stops, but those have been getting quite low recently, and I can't think of any other rea...