Skip to content

Commit 1fa6b5f

Browse files
committed
Fix #269.
1 parent 88de8c3 commit 1fa6b5f

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

html/data-locality.html

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,39 @@ <h1 class="book"><a href="/">Game Programming Patterns</a><span class="section">
3535
<h2><a href="#intent" name="intent">Intent</a></h2>
3636
<p><em>Accelerate memory access by arranging data to take advantage of CPU caching.</em></p>
3737
<h2><a href="#motivation" name="motivation">Motivation</a></h2>
38-
<p>We&#8217;ve been lied to. They keep showing us charts where CPU speed goes up and up every year as if Moore&#8217;s Law isn&#8217;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.</p>
39-
<p>Chips <em>have</em> been getting faster (though even that&#8217;s plateauing now), but the hardware heads failed to mention something. Sure, we can <em>process</em> data faster than ever, but we can&#8217;t <em>get</em> that data faster.</p>
38+
<p>We&#8217;ve been lied to. They keep showing us charts where CPU speed goes up and up
39+
every year as if Moore&#8217;s Law isn&#8217;t just a historical observation but some kind
40+
of divine right. Without lifting a finger, we software folks watch our programs
41+
magically accelerate just by virtue of new hardware.</p>
42+
<p>Chips <em>have</em> been getting faster (though even that&#8217;s plateauing now), but the
43+
hardware heads failed to mention something. Sure, we can <em>process</em> data faster
44+
than ever, but we can&#8217;t <em>get</em> that data faster.</p>
4045
<p><span name="legend"></span></p>
4146
<p><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." /></p>
4247
<aside name="legend">
4348

44-
<p>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.</p>
49+
<p>Processor and RAM speed relative to their respective speeds in 1980. As you can
50+
see, CPUs have grown in leaps and bounds, but RAM access is lagging far behind.</p>
4551
<p>Data for this is from <em>Computer Architecture: A Quantitative Approach</em>
46-
by John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau by way of Tony Albrecht&#8217;s &#8220;<a href="http://seven-degrees-of-freedom.blogspot.com/2009/12/pitfalls-of-object-oriented-programming.html">Pitfalls of Object-Oriented Programming</a>&rdquo;.</p>
52+
by John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau by way of Tony
53+
Albrecht&#8217;s &#8220;<a href="http://seven-degrees-of-freedom.blogspot.com/2009/12/pitfalls-of-object-oriented-programming.html">Pitfalls of Object-Oriented Programming</a>&rdquo;.</p>
4754
</aside>
4855

49-
<p>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&#8217;t been keeping up with increasing CPU speeds. Not even close.</p>
50-
<p>With today&#8217;s hardware, it can take <em>hundreds</em> 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&#8217;t sitting idle 99% of the time waiting for data?</p>
51-
<p>Actually, they <em>are</em> stuck waiting on memory an astonishingly large fraction of time these days, but it&#8217;s not as bad as it could be. To explain how, let&#8217;s take a trip to the Land of Overly Long Analogies&#8230;</p>
56+
<p>For your super-fast CPU to blow through a ream of calculations, it actually has
57+
to get the data out of main memory and into registers. As you can see, RAM hasn&#8217;t
58+
been keeping up with increasing CPU speeds. Not even close.</p>
59+
<p>With today&#8217;s hardware, it can take <em>hundreds</em> of cycles to fetch a byte of data
60+
from <span name="ram">RAM</span>. If most instructions need data, and it takes
61+
hundreds of cycles to get it, how is it that our CPUs aren&#8217;t sitting idle 99%
62+
of the time waiting for data?</p>
63+
<p>Actually, they <em>are</em> stuck waiting on memory an astonishingly large fraction of
64+
time these days, but it&#8217;s not as bad as it could be. To explain how, let&#8217;s take
65+
a trip to the Land of Overly Long Analogies&#8230;</p>
5266
<aside name="ram">
5367

54-
<p>It&#8217;s called &#8220;random access memory&#8221; because, unlike disc drives, you can theoretically access any piece of it as quick as any other. You don&#8217;t have to worry about reading things consecutively like you do a disc.</p>
68+
<p>It&#8217;s called &#8220;random access memory&#8221; because, unlike disc drives, you can
69+
theoretically access any piece of it as quick as any other. You don&#8217;t have
70+
to worry about reading things consecutively like you do a disc.</p>
5571
<p>Or, at least, you <em>didn&#8217;t</em>. As we&#8217;ll see, RAM isn&#8217;t so random access anymore.</p>
5672
</aside>
5773

@@ -518,7 +534,8 @@ <h3><a href="#contiguous-arrays" name="contiguous-arrays">Contiguous arrays</a><
518534
it was doing that before to ensure they were processed in the right order. Even
519535
so, each component itself is still nicely encapsulated. It owns its own data and
520536
methods. We simply changed the way it&#8217;s used.</p>
521-
<p>This doesn&#8217;t mean we need to get rid of <code>GameEntity</code> either. We can leave it as it is with pointers to its components. They&#8217;ll just point into those
537+
<p>This doesn&#8217;t mean we need to get rid of <code>GameEntity</code> either. We can leave it as it
538+
is with pointers to its components. They&#8217;ll just point into those
522539
arrays. This is still useful for other parts of the game where you want to pass
523540
around a conceptual &#8220;game entity&#8221; and everything that goes with it. The
524541
important part is that the performance-critical game loop sidesteps that and

html/observer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ <h3><a href="#observable-physics" name="observable-physics">Observable physics</
311311
game programmers what
312312
they think about this pattern, they bring up a few complaints. Let&#8217;s see what we
313313
can do to address them, if anything.</p>
314-
<h2><a href="#"it's-too-slow"" name=""it's-too-slow"">&#8220;It&#8217;s Too Slow&#8221;</a></h2>
314+
<h2><a href="#it's-too-slow" name="it's-too-slow">&#8220;It&#8217;s Too Slow&#8221;</a></h2>
315315
<p>I hear this a lot, often from programmers who don&#8217;t actually know the details of
316316
the pattern. They have a default assumption that anything that smells like a
317317
&#8220;design pattern&#8221; must involve piles of classes and indirection and other
@@ -358,7 +358,7 @@ <h3><a href="#it's-too-*fast*" name="it's-too-*fast*">It&#8217;s too <em>fast?</
358358
deadlock the game. In a highly threaded engine, you may be better off with
359359
asynchronous communication using an <a href="event-queue.html"
360360
class="pattern">Event Queue</a>.</p>
361-
<h2><a href="#"it-does-too-much-dynamic-allocation"" name=""it-does-too-much-dynamic-allocation"">&#8220;It Does Too Much Dynamic Allocation&#8221;</a></h2>
361+
<h2><a href="#it-does-too-much-dynamic-allocation" name="it-does-too-much-dynamic-allocation">&#8220;It Does Too Much Dynamic Allocation&#8221;</a></h2>
362362
<p>Whole tribes of the programmer clan&#8202;&mdash;&#8202;including many game developers&#8202;&mdash;&#8202;have
363363
moved onto garbage collected languages, and dynamic allocation isn&#8217;t the boogie
364364
man that it used to be. But for performance-critical software like games, memory

script/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def format_file(path, nav, skip_up_to_date):
160160
headertype = stripped[:index]
161161
header = pretty(stripped[index:].strip())
162162
anchor = header.lower().replace(' ', '-')
163-
anchor = anchor.translate(None, '.?!:/')
163+
anchor = anchor.translate(None, '.?!:/"')
164164

165165
# Add an anchor to the header.
166166
contents += indentation + headertype

0 commit comments

Comments
 (0)