|
7 | 7 |
|
8 | 8 | ## Motivation
|
9 | 9 |
|
10 |
| -We've been lied to. They keep showing us charts where CPU speed goes up and up every year as if Moore's Law isn't just a historical observation but some kind of divine right. Without lifting a finger, we software folks watch our programs magically accelerate just by virtue of new hardware. |
| 10 | +We've been lied to. They keep showing us charts where CPU speed goes up and up |
| 11 | +every year as if Moore's Law isn't just a historical observation but some kind |
| 12 | +of divine right. Without lifting a finger, we software folks watch our programs |
| 13 | +magically accelerate just by virtue of new hardware. |
11 | 14 |
|
12 |
| -Chips *have* been getting faster (though even that's plateauing now), but the hardware heads failed to mention something. Sure, we can *process* data faster than ever, but we can't *get* that data faster. |
| 15 | +Chips *have* been getting faster (though even that's plateauing now), but the |
| 16 | +hardware heads failed to mention something. Sure, we can *process* data faster |
| 17 | +than ever, but we can't *get* that data faster. |
13 | 18 |
|
14 | 19 | <span name="legend"></span>
|
15 | 20 |
|
16 | 21 | <img src="images/data-locality-chart.png" alt="A chart showing processor and RAM speed from 1980 to 2010. Processor speed increases quickly, but RAM speed lags behind." />
|
17 | 22 |
|
18 | 23 | <aside name="legend">
|
19 | 24 |
|
20 |
| -Processor and RAM speed relative to their respective speeds in 1980. As you can see, CPUs have grown in leaps and bounds, but RAM access is lagging far behind. |
| 25 | +Processor and RAM speed relative to their respective speeds in 1980. As you can |
| 26 | +see, CPUs have grown in leaps and bounds, but RAM access is lagging far behind. |
21 | 27 |
|
22 | 28 | Data for this is from *Computer Architecture: A Quantitative Approach*
|
23 |
| -by John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau by way of Tony Albrecht's "[Pitfalls of Object-Oriented Programming][poop]”. |
| 29 | +by John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau by way of Tony |
| 30 | +Albrecht's "[Pitfalls of Object-Oriented Programming][poop]”. |
24 | 31 |
|
25 | 32 | [poop]: http://seven-degrees-of-freedom.blogspot.com/2009/12/pitfalls-of-object-oriented-programming.html
|
26 | 33 |
|
27 | 34 | </aside>
|
28 | 35 |
|
29 |
| -For your super-fast CPU to blow through a ream of calculations, it actually has to get the data out of main memory and into registers. As you can see, RAM hasn't been keeping up with increasing CPU speeds. Not even close. |
| 36 | +For your super-fast CPU to blow through a ream of calculations, it actually has |
| 37 | +to get the data out of main memory and into registers. As you can see, RAM hasn't |
| 38 | +been keeping up with increasing CPU speeds. Not even close. |
30 | 39 |
|
31 |
| -With today's hardware, it can take *hundreds* of cycles to fetch a byte of data from <span name="ram">RAM</span>. If most instructions need data, and it takes hundreds of cycles to get it, how is it that our CPUs aren't sitting idle 99% of the time waiting for data? |
| 40 | +With today's hardware, it can take *hundreds* of cycles to fetch a byte of data |
| 41 | +from <span name="ram">RAM</span>. If most instructions need data, and it takes |
| 42 | +hundreds of cycles to get it, how is it that our CPUs aren't sitting idle 99% |
| 43 | +of the time waiting for data? |
32 | 44 |
|
33 |
| -Actually, they *are* stuck waiting on memory an astonishingly large fraction of time these days, but it's not as bad as it could be. To explain how, let's take a trip to the Land of Overly Long Analogies... |
| 45 | +Actually, they *are* stuck waiting on memory an astonishingly large fraction of |
| 46 | +time these days, but it's not as bad as it could be. To explain how, let's take |
| 47 | +a trip to the Land of Overly Long Analogies... |
34 | 48 |
|
35 | 49 | <aside name="ram">
|
36 | 50 |
|
37 |
| -It's called "random access memory" because, unlike disc drives, you can theoretically access any piece of it as quick as any other. You don't have to worry about reading things consecutively like you do a disc. |
| 51 | +It's called "random access memory" because, unlike disc drives, you can |
| 52 | +theoretically access any piece of it as quick as any other. You don't have |
| 53 | +to worry about reading things consecutively like you do a disc. |
38 | 54 |
|
39 | 55 | Or, at least, you *didn't*. As we'll see, RAM isn't so random access anymore.
|
40 | 56 |
|
@@ -460,7 +476,8 @@ it was doing that before to ensure they were processed in the right order. Even
|
460 | 476 | so, each component itself is still nicely encapsulated. It owns its own data and
|
461 | 477 | methods. We simply changed the way it's used.
|
462 | 478 |
|
463 |
| -This doesn't mean we need to get rid of `GameEntity` either. We can leave it as it is with pointers to its components. They'll just point into those |
| 479 | +This doesn't mean we need to get rid of `GameEntity` either. We can leave it as it |
| 480 | +is with pointers to its components. They'll just point into those |
464 | 481 | arrays. This is still useful for other parts of the game where you want to pass
|
465 | 482 | around a conceptual "game entity" and everything that goes with it. The
|
466 | 483 | important part is that the performance-critical game loop sidesteps that and
|
|
0 commit comments