9:59:59.000,9:59:59.000 So hi there, everyone. 9:59:59.000,9:59:59.000 My name is Chandler Carruth. 9:59:59.000,9:59:59.000 I work for Google 9:59:59.000,9:59:59.000 I work on our C++ language platform 9:59:59.000,9:59:59.000 I work on our C++ compilers 9:59:59.000,9:59:59.000 specifically the Clang and LLVM teams at Google 9:59:59.000,9:59:59.000 And I'm here to talk to you a little about performance. 9:59:59.000,9:59:59.000 and efficiency, and making code fast, 9:59:59.000,9:59:59.000 and all the different things that go into that. 9:59:59.000,9:59:59.000 But before I do too much 9:59:59.000,9:59:59.000 I want to give actually give you guys a little bit of 9:59:59.000,9:59:59.000 one might say are expectations. 9:59:59.000,9:59:59.000 Because I have been reading the twitter feed 9:59:59.000,9:59:59.000 from all these folks, that talk about 9:59:59.000,9:59:59.000 all these crazy good questions 9:59:59.000,9:59:59.000 I just want you guys to essentially know 9:59:59.000,9:59:59.000 this is my view 9:59:59.000,9:59:59.000 of what Performance 101 should be. 9:59:59.000,9:59:59.000 Okay? This is going to be kind of an intro talk. 9:59:59.000,9:59:59.000 You guys are hard core, really deep performance nuts. 9:59:59.000,9:59:59.000 You may be a little bit bored, and please be kind, 9:59:59.000,9:59:59.000 because I'm going to gloss over some things 9:59:59.000,9:59:59.000 you could heckle me thoroughly if you really want to 9:59:59.000,9:59:59.000 We're going to talk about efficiency, performance, 9:59:59.000,9:59:59.000 algorithms and data structures. 9:59:59.000,9:59:59.000 And the first thing we are going to do is we're not going to talk about them. 9:59:59.000,9:59:59.000 We're going to talk about why anyone cares about them. 9:59:59.000,9:59:59.000 How many folks here think it's really important 9:59:59.000,9:59:59.000 to have high performance in C++? 9:59:59.000,9:59:59.000 Raise your hand if think that it's super important. 9:59:59.000,9:59:59.000 Everyone thinks it's important! 9:59:59.000,9:59:59.000 And the folks here who have a really clear idea why performance is important. 9:59:59.000,9:59:59.000 Now, all the people who didn't raise their hands the second time, 9:59:59.000,9:59:59.000 Please reconsider raising your hand the first time. 9:59:59.000,9:59:59.000 We actually need to understand why performance is important in C++, 9:59:59.000,9:59:59.000 before we actually decide it's important, we're going to care a lot about it. 9:59:59.000,9:59:59.000 I'm going to tell you why I care about performance in C++. 9:59:59.000,9:59:59.000 Most of it comes down to a quote from Nicolas Werth. 9:59:59.000,9:59:59.000 Which I will try to pronounce correctly but fail miserably. 9:59:59.000,9:59:59.000 I actually really like a lot of our stuff, 9:59:59.000,9:59:59.000 I think he encapsulates a lot of my thoughts, 9:59:59.000,9:59:59.000 what's core to my philosophy here. 9:59:59.000,9:59:59.000 The software is getting slower more rapidly than 9:59:59.000,9:59:59.000 hardware becomes faster. 9:59:59.000,9:59:59.000 This is particularly in contrast to 9:59:59.000,9:59:59.000 the kind of normal Moore's Law approach: 9:59:59.000,9:59:59.000 Hardware's getting faster, all the time 9:59:59.000,9:59:59.000 it's okay, we don't need to make software faster, 9:59:59.000,9:59:59.000 because the hardware will catch up. 9:59:59.000,9:59:59.000 And it turns out that's not really true. 9:59:59.000,9:59:59.000 We're really good at writing slow software. 9:59:59.000,9:59:59.000 Even in C++, we're really good at writing slow software. 9:59:59.000,9:59:59.000 It's hard to write fast software, 9:59:59.000,9:59:59.000 and it takes a lot of effort. 9:59:59.000,9:59:59.000 And so it's important to think about 9:59:59.000,9:59:59.000 why that might matter no matter how fast 9:59:59.000,9:59:59.000 the processors get. 9:59:59.000,9:59:59.000 And to give you an idea of just how much 9:59:59.000,9:59:59.000 I think Nicholas Werth is on the same page 9:59:59.000,9:59:59.000 I just have to mention he actually wrote a book 9:59:59.000,9:59:59.000 entitled Algorithms + Data Structures = Programs. 9:59:59.000,9:59:59.000 I did not realize this as I was picking 9:59:59.000,9:59:59.000 the title of the topic. 9:59:59.000,9:59:59.000 Anyways, we're going to come back 9:59:59.000,9:59:59.000 to the title of this book. 9:59:59.000,9:59:59.000 Because he predicted some whole elements 9:59:59.000,9:59:59.000 of this talk in this book. 9:59:59.000,9:59:59.000 So how many folks here have read this book? 9:59:59.000,9:59:59.000 Anyone? All right! A long time ago. 9:59:59.000,9:59:59.000 It's a good book. It's a good book. 9:59:59.000,9:59:59.000 Okay, so I actually think the idea that 9:59:59.000,9:59:59.000 software is getting slower too quickly, right? 9:59:59.000,9:59:59.000 is really getting slower at an astonishing 9:59:59.000,9:59:59.000 rate is even more important than before. 9:59:59.000,9:59:59.000 And for pretty specific reasons. 9:59:59.000,9:59:59.000 There was a very seminal event that 9:59:59.000,9:59:59.000 happened in the technology world some time ago 9:59:59.000,9:59:59.000 that changed, in my opinion and a lot of 9:59:59.000,9:59:59.000 other peoples' opinion, how we look at 9:59:59.000,9:59:59.000 computing devices, the performance of 9:59:59.000,9:59:59.000 computing devices, the challenges we face 9:59:59.000,9:59:59.000 running software for computing devices. 9:59:59.000,9:59:59.000 And this event was the iPhone. Okay? 9:59:59.000,9:59:59.000 And when Steve Jobs introduced the iPhone, 9:59:59.000,9:59:59.000 he was not doing anything particular to C++ 9:59:59.000,9:59:59.000 but he was changing how we 9:59:59.000,9:59:59.000 think about computing. 9:59:59.000,9:59:59.000 Mobile was now a first class compute citizen. 9:59:59.000,9:59:59.000 It took the world a little while to even 9:59:59.000,9:59:59.000 realize that that was what had happened that day. 9:59:59.000,9:59:59.000 But that's what happened. 9:59:59.000,9:59:59.000 We now have to care about mobile. 9:59:59.000,9:59:59.000 We have to care about things that are small. 9:59:59.000,9:59:59.000 Right? things that are hard and challenging 9:59:59.000,9:59:59.000 to fit big bulky systems into. 9:59:59.000,9:59:59.000 And we essentially get into this annoying 9:59:59.000,9:59:59.000 situation of, we have small, we have fast 9:59:59.000,9:59:59.000 machines. We have to choose one. 9:59:59.000,9:59:59.000 We don't get to choose though. 9:59:59.000,9:59:59.000 We're going to choose small almost every time. 9:59:59.000,9:59:59.000 But it gets worse. 9:59:59.000,9:59:59.000 Because the other problem that the iPhone 9:59:59.000,9:59:59.000 introduced that people weren't 9:59:59.000,9:59:59.000 really focused on at the time 9:59:59.000,9:59:59.000 was the problem of a battery. 9:59:59.000,9:59:59.000 What do we do about the battery in your phone? 9:59:59.000,9:59:59.000 You phone's battery, I mean my phone's 9:59:59.000,9:59:59.000 battery is about dead. Right? 9:59:59.000,9:59:59.000 How many folks here have charged their 9:59:59.000,9:59:59.000 phone today? (Laughter from audience) Okay? 9:59:59.000,9:59:59.000 That's a problem. That's not a feature. 9:59:59.000,9:59:59.000 That's a bug. (Laughter from audience) Okay? 9:59:59.000,9:59:59.000 Yes, How many folks are charging their phone now? 9:59:59.000,9:59:59.000 (Laughter from audience) Okay so we kind of 9:59:59.000,9:59:59.000 entered this new problem domain, suddenly 9:59:59.000,9:59:59.000 power became relevant. 9:59:59.000,9:59:59.000 There's some kind of shady research I want 9:59:59.000,9:59:59.000 to push back against. 9:59:59.000,9:59:59.000 There's some research into power efficient 9:59:59.000,9:59:59.000 instructions. If you ever read about power 9:59:59.000,9:59:59.000 efficient instructions or optimizing 9:59:59.000,9:59:59.000 power usage, you should become very suspicious. 9:59:59.000,9:59:59.000 And you should probably run the other direction. 9:59:59.000,9:59:59.000 Because this is mostly total junk science. Okay? 9:59:59.000,9:59:59.000 Here's the number one leading theory 9:59:59.000,9:59:59.000 about how to save this, how to save 9:59:59.000,9:59:59.000 battery life. Finish running the program. 9:59:59.000,9:59:59.000 (Audience laughter) Seriously, race to sleep. 9:59:59.000,9:59:59.000 That's the actual technical term, race to sleep. 9:59:59.000,9:59:59.000 The faster your software runs, the less 9:59:59.000,9:59:59.000 power it consumes. Now people get really 9:59:59.000,9:59:59.000 upset about this. No, no if I run 9:59:59.000,9:59:59.000 software really fast, then it heats up my 9:59:59.000,9:59:59.000 processor, all that excess heat, that's the 9:59:59.000,9:59:59.000 wasted power. But it's not, okay? Here's 9:59:59.000,9:59:59.000 the thing, we've never really figured out 9:59:59.000,9:59:59.000 how to run processors and do work 9:59:59.000,9:59:59.000 on processors in a 9:59:59.000,9:59:59.000 power efficient way. Do you know what we 9:59:59.000,9:59:59.000 have figured out how to do with processors 9:59:59.000,9:59:59.000 that has made our battery lives improve 9:59:59.000,9:59:59.000 over time? We figured out how to turn them off. 9:59:59.000,9:59:59.000 This is literally how your phone, your 9:59:59.000,9:59:59.000 laptop, like if you have your computer 9:59:59.000,9:59:59.000 on your desk. Every single 9:59:59.000,9:59:59.000 microprocessor, general purpose 9:59:59.000,9:59:59.000 microprocessors you can get today. 9:59:59.000,9:59:59.000 The way it conserves power is by 9:59:59.000,9:59:59.000 turning itself off as rapidly and as 9:59:59.000,9:59:59.000 frequently as possible for as long a 9:59:59.000,9:59:59.000 period time as possible. The more 9:59:59.000,9:59:59.000 your processor turns on, the less this 9:59:59.000,9:59:59.000 little green goes yellow and then red. 9:59:59.000,9:59:59.000 Bad stuff right? So we actually want to 9:59:59.000,9:59:59.000 make code faster in order to save battery 9:59:59.000,9:59:59.000 life. Universally, this is true. 9:59:59.000,9:59:59.000 There are some extreme exceptions to it 9:59:59.000,9:59:59.000 There'e some really weird stuff around 9:59:59.000,9:59:59.000 out on the fringe. But 99.999999% of the time 9:59:59.000,9:59:59.000 You want to run code faster to save 9:59:59.000,9:59:59.000 battery. But batteries aren't the only 9:59:59.000,9:59:59.000 story when it comes to saving power. 9:59:59.000,9:59:59.000 This is one of Google's data centers. 9:59:59.000,9:59:59.000 You'll note that this is a very large building 9:59:59.000,9:59:59.000 and the only thing it is doing is taking 9:59:59.000,9:59:59.000 electricity and turning it into heat. 9:59:59.000,9:59:59.000 That is it's job. And it's really good 9:59:59.000,9:59:59.000 at it's job. And unfortunately, 9:59:59.000,9:59:59.000 electricity costs a lot of money. 9:59:59.000,9:59:59.000 And in fact, it's a finite resource. 9:59:59.000,9:59:59.000 There's a certain point at which the cost 9:59:59.000,9:59:59.000 goes away, you simply cannot have any 9:59:59.000,9:59:59.000 more electricity at a particular point 9:59:59.000,9:59:59.000 in time. And so power becomes very, very 9:59:59.000,9:59:59.000 important in a data center as well. 9:59:59.000,9:59:59.000 And I find it interesting that it's on the 9:59:59.000,9:59:59.000 two extremes of computing platforms that 9:59:59.000,9:59:59.000 we find convergence. Right? When you drop 9:59:59.000,9:59:59.000 to a phone, or you go up to a data center 9:59:59.000,9:59:59.000 all of a sudden power dominates. Right? 9:59:59.000,9:59:59.000 We'll talk about compute per watt. 9:59:59.000,9:59:59.000 This is another picture of the data center 9:59:59.000,9:59:59.000 by the way. I just want to clarify what 9:59:59.000,9:59:59.000 this is. This is one of my favorite pictures 9:59:59.000,9:59:59.000 Those are enormous vents blowing out stem vapor. 9:59:59.000,9:59:59.000 I don't know much about this but 9:59:59.000,9:59:59.000 apparently when you can see the water vapor 9:59:59.000,9:59:59.000 the data center is operating at peak 9:59:59.000,9:59:59.000 efficiency because it means it's not too hot, 9:59:59.000,9:59:59.000 its not too cool, its actually efficiently 9:59:59.000,9:59:59.000 cooling the ?. Anyway this is trivia. 9:59:59.000,9:59:59.000 So the compute per watt tends to 9:59:59.000,9:59:59.000 dominate in the data canter and this is 9:59:59.000,9:59:59.000 actually kind of the same thing we're trying 9:59:59.000,9:59:59.000 to pull off on a phone or anything else. 9:59:59.000,9:59:59.000 We want to maximize how much compute 9:59:59.000,9:59:59.000 we can get out of the watts we're going 9:59:59.000,9:59:59.000 to burn when the chip is turned on. 9:59:59.000,9:59:59.000 Makes sense? Alright? Now I say raw speed 9:59:59.000,9:59:59.000 isn't everything because when we talk 9:59:59.000,9:59:59.000 about performance is really important 9:59:59.000,9:59:59.000 you'll get some mixed messages from people. 9:59:59.000,9:59:59.000 How many folks have heard this adage: 9:59:59.000,9:59:59.000 After all, Java is faster than C++ 9:59:59.000,9:59:59.000 how many folks have heard it? 9:59:59.000,9:59:59.000 Oh, you can be honest, I've heard it! 9:59:59.000,9:59:59.000 All right, I had James Gosling sit across 9:59:59.000,9:59:59.000 from the table and tell me 9:59:59.000,9:59:59.000 I was a complete moron because I didn't 9:59:59.000,9:59:59.000 believe Java that was faster than C++. 9:59:59.000,9:59:59.000 And at the time he was right. 9:59:59.000,9:59:59.000 And I learned better. 9:59:59.000,9:59:59.000 So it turns out that Java is faster than C++ 9:59:59.000,9:59:59.000 in certain areas and scenarios. 9:59:59.000,9:59:59.000 For example if you have a specific application 9:59:59.000,9:59:59.000 and your specific application is going to 9:59:59.000,9:59:59.000 run for a long period of time 9:59:59.000,9:59:59.000 and you're concerned about the ? 9:59:59.000,9:59:59.000 of the application and you have a 9:59:59.000,9:59:59.000 very well tuned virtual machine 9:59:59.000,9:59:59.000 for your Java, and you've tuned 9:59:59.000,9:59:59.000 the garbage collector to precisely match 9:59:59.000,9:59:59.000 the desired kind of garbage collection 9:59:59.000,9:59:59.000 interruption frequency for your application 9:59:59.000,9:59:59.000 If you get all of that, Java will 9:59:59.000,9:59:59.000 very often