1 99:59:59,999 --> 99:59:59,999 So hi there, everyone. 2 99:59:59,999 --> 99:59:59,999 My name is Chandler Carruth. 3 99:59:59,999 --> 99:59:59,999 I work for Google 4 99:59:59,999 --> 99:59:59,999 I work on our C++ language platform 5 99:59:59,999 --> 99:59:59,999 I work on our C++ compilers 6 99:59:59,999 --> 99:59:59,999 specifically the Clang and LLVM teams at Google 7 99:59:59,999 --> 99:59:59,999 And I'm here to talk to you a little about performance. 8 99:59:59,999 --> 99:59:59,999 and efficiency, and making code fast, 9 99:59:59,999 --> 99:59:59,999 and all the different things that go into that. 10 99:59:59,999 --> 99:59:59,999 But before I do too much 11 99:59:59,999 --> 99:59:59,999 I want to give actually give you guys a little bit of 12 99:59:59,999 --> 99:59:59,999 one might say are expectations. 13 99:59:59,999 --> 99:59:59,999 Because I have been reading the twitter feed 14 99:59:59,999 --> 99:59:59,999 from all these folks, that talk about 15 99:59:59,999 --> 99:59:59,999 all these crazy good questions 16 99:59:59,999 --> 99:59:59,999 I just want you guys to essentially know 17 99:59:59,999 --> 99:59:59,999 this is my view 18 99:59:59,999 --> 99:59:59,999 of what Performance 101 should be. 19 99:59:59,999 --> 99:59:59,999 Okay? This is going to be kind of an intro talk. 20 99:59:59,999 --> 99:59:59,999 You guys are hard core, really deep performance nuts. 21 99:59:59,999 --> 99:59:59,999 You may be a little bit bored, and please be kind, 22 99:59:59,999 --> 99:59:59,999 because I'm going to gloss over some things 23 99:59:59,999 --> 99:59:59,999 you could heckle me thoroughly if you really want to 24 99:59:59,999 --> 99:59:59,999 We're going to talk about efficiency, performance, 25 99:59:59,999 --> 99:59:59,999 algorithms and data structures. 26 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. 27 99:59:59,999 --> 99:59:59,999 We're going to talk about why anyone cares about them. 28 99:59:59,999 --> 99:59:59,999 How many folks here think it's really important 29 99:59:59,999 --> 99:59:59,999 to have high performance in C++? 30 99:59:59,999 --> 99:59:59,999 Raise your hand if think that it's super important. 31 99:59:59,999 --> 99:59:59,999 Everyone thinks it's important! 32 99:59:59,999 --> 99:59:59,999 And the folks here who have a really clear idea why performance is important. 33 99:59:59,999 --> 99:59:59,999 Now, all the people who didn't raise their hands the second time, 34 99:59:59,999 --> 99:59:59,999 Please reconsider raising your hand the first time. 35 99:59:59,999 --> 99:59:59,999 We actually need to understand why performance is important in C++, 36 99:59:59,999 --> 99:59:59,999 before we actually decide it's important, we're going to care a lot about it. 37 99:59:59,999 --> 99:59:59,999 I'm going to tell you why I care about performance in C++. 38 99:59:59,999 --> 99:59:59,999 Most of it comes down to a quote from Nicolas Werth. 39 99:59:59,999 --> 99:59:59,999 Which I will try to pronounce correctly but fail miserably. 40 99:59:59,999 --> 99:59:59,999 I actually really like a lot of our stuff, 41 99:59:59,999 --> 99:59:59,999 I think he encapsulates a lot of my thoughts, 42 99:59:59,999 --> 99:59:59,999 what's core to my philosophy here. 43 99:59:59,999 --> 99:59:59,999 The software is getting slower more rapidly than 44 99:59:59,999 --> 99:59:59,999 hardware becomes faster. 45 99:59:59,999 --> 99:59:59,999 This is particularly in contrast to 46 99:59:59,999 --> 99:59:59,999 the kind of normal Moore's Law approach: 47 99:59:59,999 --> 99:59:59,999 Hardware's getting faster, all the time 48 99:59:59,999 --> 99:59:59,999 it's okay, we don't need to make software faster, 49 99:59:59,999 --> 99:59:59,999 because the hardware will catch up. 50 99:59:59,999 --> 99:59:59,999 And it turns out that's not really true. 51 99:59:59,999 --> 99:59:59,999 We're really good at writing slow software. 52 99:59:59,999 --> 99:59:59,999 Even in C++, we're really good at writing slow software. 53 99:59:59,999 --> 99:59:59,999 It's hard to write fast software, 54 99:59:59,999 --> 99:59:59,999 and it takes a lot of effort. 55 99:59:59,999 --> 99:59:59,999 And so it's important to think about 56 99:59:59,999 --> 99:59:59,999 why that might matter no matter how fast 57 99:59:59,999 --> 99:59:59,999 the processors get. 58 99:59:59,999 --> 99:59:59,999 And to give you an idea of just how much 59 99:59:59,999 --> 99:59:59,999 I think Nicholas Werth is on the same page 60 99:59:59,999 --> 99:59:59,999 I just have to mention he actually wrote a book 61 99:59:59,999 --> 99:59:59,999 entitled Algorithms + Data Structures = Programs. 62 99:59:59,999 --> 99:59:59,999 I did not realize this as I was picking 63 99:59:59,999 --> 99:59:59,999 the title of the topic. 64 99:59:59,999 --> 99:59:59,999 Anyways, we're going to come back 65 99:59:59,999 --> 99:59:59,999 to the title of this book. 66 99:59:59,999 --> 99:59:59,999 Because he predicted some whole elements 67 99:59:59,999 --> 99:59:59,999 of this talk in this book. 68 99:59:59,999 --> 99:59:59,999 So how many folks here have read this book? 69 99:59:59,999 --> 99:59:59,999 Anyone? All right! A long time ago. 70 99:59:59,999 --> 99:59:59,999 It's a good book. It's a good book. 71 99:59:59,999 --> 99:59:59,999 Okay, so I actually think the idea that 72 99:59:59,999 --> 99:59:59,999 software is getting slower too quickly, right? 73 99:59:59,999 --> 99:59:59,999 is really getting slower at an astonishing 74 99:59:59,999 --> 99:59:59,999 rate is even more important than before. 75 99:59:59,999 --> 99:59:59,999 And for pretty specific reasons. 76 99:59:59,999 --> 99:59:59,999 There was a very seminal event that 77 99:59:59,999 --> 99:59:59,999 happened in the technology world some time ago 78 99:59:59,999 --> 99:59:59,999 that changed, in my opinion and a lot of 79 99:59:59,999 --> 99:59:59,999 other peoples' opinion, how we look at 80 99:59:59,999 --> 99:59:59,999 computing devices, the performance of 81 99:59:59,999 --> 99:59:59,999 computing devices, the challenges we face 82 99:59:59,999 --> 99:59:59,999 running software for computing devices. 83 99:59:59,999 --> 99:59:59,999 And this event was the iPhone. Okay? 84 99:59:59,999 --> 99:59:59,999 And when Steve Jobs introduced the iPhone, 85 99:59:59,999 --> 99:59:59,999 he was not doing anything particular to C++ 86 99:59:59,999 --> 99:59:59,999 but he was changing how we 87 99:59:59,999 --> 99:59:59,999 think about computing. 88 99:59:59,999 --> 99:59:59,999 Mobile was now a first class compute citizen. 89 99:59:59,999 --> 99:59:59,999 It took the world a little while to even 90 99:59:59,999 --> 99:59:59,999 realize that that was what had happened that day. 91 99:59:59,999 --> 99:59:59,999 But that's what happened. 92 99:59:59,999 --> 99:59:59,999 We now have to care about mobile. 93 99:59:59,999 --> 99:59:59,999 We have to care about things that are small. 94 99:59:59,999 --> 99:59:59,999 Right? things that are hard and challenging 95 99:59:59,999 --> 99:59:59,999 to fit big bulky systems into. 96 99:59:59,999 --> 99:59:59,999 And we essentially get into this annoying 97 99:59:59,999 --> 99:59:59,999 situation of, we have small, we have fast 98 99:59:59,999 --> 99:59:59,999 machines. We have to choose one. 99 99:59:59,999 --> 99:59:59,999 We don't get to choose though. 100 99:59:59,999 --> 99:59:59,999 We're going to choose small almost every time. 101 99:59:59,999 --> 99:59:59,999 But it gets worse. 102 99:59:59,999 --> 99:59:59,999 Because the other problem that the iPhone 103 99:59:59,999 --> 99:59:59,999 introduced that people weren't 104 99:59:59,999 --> 99:59:59,999 really focused on at the time 105 99:59:59,999 --> 99:59:59,999 was the problem of a battery. 106 99:59:59,999 --> 99:59:59,999 What do we do about the battery in your phone? 107 99:59:59,999 --> 99:59:59,999 You phone's battery, I mean my phone's 108 99:59:59,999 --> 99:59:59,999 battery is about dead. Right? 109 99:59:59,999 --> 99:59:59,999 How many folks here have charged their 110 99:59:59,999 --> 99:59:59,999 phone today? (Laughter from audience) Okay? 111 99:59:59,999 --> 99:59:59,999 That's a problem. That's not a feature. 112 99:59:59,999 --> 99:59:59,999 That's a bug. (Laughter from audience) Okay? 113 99:59:59,999 --> 99:59:59,999 Yes, How many folks are charging their phone now? 114 99:59:59,999 --> 99:59:59,999 (Laughter from audience) Okay so we kind of 115 99:59:59,999 --> 99:59:59,999 entered this new problem domain, suddenly 116 99:59:59,999 --> 99:59:59,999 power became relevant. 117 99:59:59,999 --> 99:59:59,999 There's some kind of shady research I want 118 99:59:59,999 --> 99:59:59,999 to push back against. 119 99:59:59,999 --> 99:59:59,999 There's some research into power efficient 120 99:59:59,999 --> 99:59:59,999 instructions. If you ever read about power 121 99:59:59,999 --> 99:59:59,999 efficient instructions or optimizing 122 99:59:59,999 --> 99:59:59,999 power usage, you should become very suspicious. 123 99:59:59,999 --> 99:59:59,999 And you should probably run the other direction. 124 99:59:59,999 --> 99:59:59,999 Because this is mostly total junk science. Okay? 125 99:59:59,999 --> 99:59:59,999 Here's the number one leading theory 126 99:59:59,999 --> 99:59:59,999 about how to save this, how to save 127 99:59:59,999 --> 99:59:59,999 battery life. Finish running the program. 128 99:59:59,999 --> 99:59:59,999 (Audience laughter) Seriously, race to sleep. 129 99:59:59,999 --> 99:59:59,999 That's the actual technical term, race to sleep. 130 99:59:59,999 --> 99:59:59,999 The faster your software runs, the less 131 99:59:59,999 --> 99:59:59,999 power it consumes. Now people get really 132 99:59:59,999 --> 99:59:59,999 upset about this. No, no if I run 133 99:59:59,999 --> 99:59:59,999 software really fast, then it heats up my 134 99:59:59,999 --> 99:59:59,999 processor, all that excess heat, that's the 135 99:59:59,999 --> 99:59:59,999 wasted power. But it's not, okay? Here's 136 99:59:59,999 --> 99:59:59,999 the thing, we've never really figured out 137 99:59:59,999 --> 99:59:59,999 how to run processors and do work 138 99:59:59,999 --> 99:59:59,999 on processors in a 139 99:59:59,999 --> 99:59:59,999 power efficient way. Do you know what we 140 99:59:59,999 --> 99:59:59,999 have figured out how to do with processors 141 99:59:59,999 --> 99:59:59,999 that has made our battery lives improve 142 99:59:59,999 --> 99:59:59,999 over time? We figured out how to turn them off. 143 99:59:59,999 --> 99:59:59,999 This is literally how your phone, your 144 99:59:59,999 --> 99:59:59,999 laptop, like if you have your computer 145 99:59:59,999 --> 99:59:59,999 on your desk. Every single 146 99:59:59,999 --> 99:59:59,999 microprocessor, general purpose 147 99:59:59,999 --> 99:59:59,999 microprocessors you can get today. 148 99:59:59,999 --> 99:59:59,999 The way it conserves power is by 149 99:59:59,999 --> 99:59:59,999 turning itself off as rapidly and as 150 99:59:59,999 --> 99:59:59,999 frequently as possible for as long a 151 99:59:59,999 --> 99:59:59,999 period time as possible. The more 152 99:59:59,999 --> 99:59:59,999 your processor turns on, the less this 153 99:59:59,999 --> 99:59:59,999 little green goes yellow and then red. 154 99:59:59,999 --> 99:59:59,999 Bad stuff right? So we actually want to 155 99:59:59,999 --> 99:59:59,999 make code faster in order to save battery 156 99:59:59,999 --> 99:59:59,999 life. Universally, this is true. 157 99:59:59,999 --> 99:59:59,999 There are some extreme exceptions to it 158 99:59:59,999 --> 99:59:59,999 There'e some really weird stuff around 159 99:59:59,999 --> 99:59:59,999 out on the fringe. But 99.999999% of the time 160 99:59:59,999 --> 99:59:59,999 You want to run code faster to save 161 99:59:59,999 --> 99:59:59,999 battery. But batteries aren't the only 162 99:59:59,999 --> 99:59:59,999 story when it comes to saving power. 163 99:59:59,999 --> 99:59:59,999 This is one of Google's data centers. 164 99:59:59,999 --> 99:59:59,999 You'll note that this is a very large building 165 99:59:59,999 --> 99:59:59,999 and the only thing it is doing is taking 166 99:59:59,999 --> 99:59:59,999 electricity and turning it into heat. 167 99:59:59,999 --> 99:59:59,999 That is it's job. And it's really good 168 99:59:59,999 --> 99:59:59,999 at it's job. And unfortunately, 169 99:59:59,999 --> 99:59:59,999 electricity costs a lot of money. 170 99:59:59,999 --> 99:59:59,999 And in fact, it's a finite resource. 171 99:59:59,999 --> 99:59:59,999 There's a certain point at which the cost 172 99:59:59,999 --> 99:59:59,999 goes away, you simply cannot have any 173 99:59:59,999 --> 99:59:59,999 more electricity at a particular point 174 99:59:59,999 --> 99:59:59,999 in time. And so power becomes very, very 175 99:59:59,999 --> 99:59:59,999 important in a data center as well. 176 99:59:59,999 --> 99:59:59,999 And I find it interesting that it's on the 177 99:59:59,999 --> 99:59:59,999 two extremes of computing platforms that 178 99:59:59,999 --> 99:59:59,999 we find convergence. Right? When you drop 179 99:59:59,999 --> 99:59:59,999 to a phone, or you go up to a data center 180 99:59:59,999 --> 99:59:59,999 all of a sudden power dominates. Right? 181 99:59:59,999 --> 99:59:59,999 We'll talk about compute per watt. 182 99:59:59,999 --> 99:59:59,999 This is another picture of the data center 183 99:59:59,999 --> 99:59:59,999 by the way. I just want to clarify what 184 99:59:59,999 --> 99:59:59,999 this is. This is one of my favorite pictures 185 99:59:59,999 --> 99:59:59,999 Those are enormous vents blowing out stem vapor. 186 99:59:59,999 --> 99:59:59,999 I don't know much about this but 187 99:59:59,999 --> 99:59:59,999 apparently when you can see the water vapor 188 99:59:59,999 --> 99:59:59,999 the data center is operating at peak 189 99:59:59,999 --> 99:59:59,999 efficiency because it means it's not too hot, 190 99:59:59,999 --> 99:59:59,999 its not too cool, its actually efficiently 191 99:59:59,999 --> 99:59:59,999 cooling the ?. Anyway this is trivia. 192 99:59:59,999 --> 99:59:59,999 So the compute per watt tends to 193 99:59:59,999 --> 99:59:59,999 dominate in the data canter and this is 194 99:59:59,999 --> 99:59:59,999 actually kind of the same thing we're trying 195 99:59:59,999 --> 99:59:59,999 to pull off on a phone or anything else. 196 99:59:59,999 --> 99:59:59,999 We want to maximize how much compute 197 99:59:59,999 --> 99:59:59,999 we can get out of the watts we're going 198 99:59:59,999 --> 99:59:59,999 to burn when the chip is turned on. 199 99:59:59,999 --> 99:59:59,999 Makes sense? Alright? Now I say raw speed 200 99:59:59,999 --> 99:59:59,999 isn't everything because when we talk 201 99:59:59,999 --> 99:59:59,999 about performance as really important 202 99:59:59,999 --> 99:59:59,999 you'll get some mixed messages from people. 203 99:59:59,999 --> 99:59:59,999 How many folks(8:34)