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