[game_edu] Feedback request on this programming lecture snippit

Ian Schreiber ai864 at yahoo.com
Tue Jun 7 16:23:03 EDT 2011


Sounds reasonable to me as a programmer. If I had any objection, it's that
saying "optimize your macro stuff" glosses over the details: these are the kinds
of optimizations that senior-level programmers get paid the big bucks for, and I
wouldn't expect an inexperienced student to just intuitively understand which of
two given architectures is more efficient. Big-O analysis takes a bit of
training and practice.

Another thing you might mention is that beyond a certain point, "optimization"
does not mean "making something better" as much as "trading off one property for
another". Generally, code that runs faster might be harder to write, or harder
to read and maintain, or less fault-tolerant, or requires more disk space or
more RAM. This is true for both macro and micro optimization. Yes, if you start
out with a horribly-designed architecture you can probably optimize a bit
without making tradeoffs, but once you get the obvious badness out of the way,
further optimization doesn't come free...

- Ian




-----Original Message-----
From: game_edu-bounces at igda.org [mailto:game_edu-bounces at igda.org] On
Behalf Of Richard Fleming
Sent: Tuesday, June 07, 2011 4:47 AM
To: game_edu at igda.org
Subject: [game_edu] Feedback request on this programming lecture snippit

Looking for general feedback on this, good/bad/what are you smoking/ect,
before I inflict it on my students


Macro and Micro Optimization

Many times on the net you will find articles and blog posts proclaiming
the evils of optimization. "Don't do it! Not until you absolutely
must!" They all cry. "Profile and measure before you try!" is another
rally cry. And this is good advice, but only for certain kinds of
optimizations. The problem is that very few of them make a distinction
between kinds of optimization, which is what I will do here.

Macro Vs. Micro
I sort optimizations into two groups: Micro and Macro. When you read a
blog post on the evils of early optimization, they are talking about
Micro optimization. This is where you take small and isolated sections
of code, and change them so they run as fast as possible. This kind of
optimization tends to create code that is very hard to read, complex,
and bug prone unless you are very careful. It can also take a lot of
effort and time. So the net is correct on this issue, avoid it until
performance degrades bad enough that you feel you must. Also, measuring
or profiling is critical. Humans are bad at guessing where performance
bottlenecks are. You can actually make things worse if you 'optimize' a
spot that doesn't need it.

Macro optimization however is different. You want to do this from the
very start. Macro optimization is optimization at the architectural
level. Do I use a list or a queue for this data structure? How about
trees, do I need a red-black tree, or perhaps a b-tree? The point here
is to examine what you need to do and come up with an architecture that
makes sense will work well. This involves knowing the language and
target platform really well. A macro optimization that works well for a
desktop app might be horrible for a mobile target, and vice versa.

Now you might look at this and wonder: Doesn't this sound a lot like
micro optimizations? I mean, it's a lot of effort and time, and didn't
you just finish saying humans are bad at guessing performance
bottlenecks? Well, yes and yes, but some things are different here.
First and foremost, you should be doing a technical design doc for your
game anyways. If you just grab a regular design document and start
coding, you are begging for trouble. You really, really need to sit
down and do some thinking on how you want to structure the code. As for
performance, we know algorithmic performance. Called 'Big O Notation',
you can tell exactly how an algorithm will perform in different cases.
Lists are constant time for insertions. The cost of bubble sort
increase exponentially with added items. These costs are known and
proven. Keeping these things in mind will help prevent the need for
micro optimization. Then there are the platform issues that I
mentioned. In C#, you have value types like integers, and then
everything else is an Object. If you pass an integer into a parameter
that expects an Object, it 'boxes' the integer by creating a new Object
to contain it. Not that big of a deal (in most cases) on a desktop, but
this will cripple you in the Compact Framework if it happens even
moderately.

So the take-away: How should you optimize? Always start with macro
optimization. If your code is an unholy mess of spaghetti logic, no
amount of micro optimization can save you. As you implement the code,
continually measure the performance. Once you notice the performance
dropping below acceptable levels, break out the profiling tools and find
that one line that is draining all of your performance.



Dragons are awesome and dragons are fun.
But if you get one angry...
then you'll be well done.
---------------------------------------
Richard Fleming
RC 332G, x4838
Interested in creating computer games?
Then check out JCCC's Game Development AA Degree!
http://www.jccc.edu/home/depts.php/1287

The information contained in this e-mail and any attachments thereto
("e-mail") is sent by the Johnson County Community College ("JCCC") and
is intended to be confidential and for the use of only the individual or
entity named above. The information may be protected by federal and
state privacy and disclosures acts or other legal rules. If the reader
of this message is not the intended recipient, you are notified that
retention, dissemination, distribution or copying of this e-mail is
strictly prohibited. If you have received this e-mail in error please
immediately notify JCCC by email reply and immediately and permanently
delete this e-mail message and any attachments thereto. Thank you.
_______________________________________________
game_edu mailing list
game_edu at igda.org
http://seven.pairlist.net/mailman/listinfo/game_edu
_______________________________________________
game_edu mailing list
game_edu at igda.org
http://seven.pairlist.net/mailman/listinfo/game_edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://seven.pairlist.net/pipermail/game_edu/attachments/20110607/452e03f0/attachment.htm>


More information about the game_edu mailing list