Skip to content

Commit cd89939

Browse files
committed
Merge branch 'patch-1' of git://github.com/marapper/game-programming-patterns into marapper-patch-1
2 parents 60a4f3e + a7fd310 commit cd89939

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

book/data-locality.markdown

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,50 @@
77

88
## Motivation
99

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.
1114

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.
1318

1419
<span name="legend"></span>
1520

1621
<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." />
1722

1823
<aside name="legend">
1924

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.
2127

2228
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]&rdquo;.
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]&rdquo;.
2431

2532
[poop]: http://seven-degrees-of-freedom.blogspot.com/2009/12/pitfalls-of-object-oriented-programming.html
2633

2734
</aside>
2835

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.
3039

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?
3244

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...
3448

3549
<aside name="ram">
3650

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.
3854

3955
Or, at least, you *didn't*. As we'll see, RAM isn't so random access anymore.
4056

@@ -460,7 +476,8 @@ it was doing that before to ensure they were processed in the right order. Even
460476
so, each component itself is still nicely encapsulated. It owns its own data and
461477
methods. We simply changed the way it's used.
462478

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
464481
arrays. This is still useful for other parts of the game where you want to pass
465482
around a conceptual "game entity" and everything that goes with it. The
466483
important part is that the performance-critical game loop sidesteps that and

0 commit comments

Comments
 (0)