Last week’s article showed how to effectively use the CPU’s caches to boost performance by an order of magnitude. Today’s article goes even further to show you how to use even more of the CPU’s capabilities!
Archive for category Unity
Most programmers write code for an abstract computer. The thing is- code runs on a real computer that works in a specific way. Even if your game is going to run on a wide range of devices, knowing some of the common features can speed up your code 10x or more. Today’s article shows you how!
Sometimes it seems like Unity programming is a minefield. Plenty of innocuous-looking code secretly creates garbage and eventually the GC runs and causes a frame hitch. Today’s article is about some of those less-obvious ways to create garbage.
JSON is incredibly bloated, but what do you use instead? Many games have some huge configuration file with lots of data about how the game should be run. Think of the items in a shop or the layout of a saga map and you’ll get the picture. This is often a JSON file that will take forever to parse, hog up a bunch of memory, and create a ton of garbage for the GC to collect. Enter CDB: the Constant Database. Unlike other databases, CDB is a simple, read-only, key-value store that’s been around over 20 years! Today’s article introduces the format and provides a one-file script you can drop into your projects and start gaining the many advantages that CDB has to offer.
It’s extremely common to see somebody ask a question about avoiding the garbage collector only to be answered with “just use a pool” as if that immediately and totally solved the problem. While pools will often keep the garbage collector at bay, they’ll also introduce a whole slew of new problems that you’ve got to deal with instead. Today’s article goes through several of these problems so you’ll be aware of the tradeoffs involved and hopefully avoid some pitfalls.
Now that Unity has a new compiler that makes foreach
loops not create garbage with List<T>
, it’s time to re-test all the kinds of loops to see if anything’s changed. This article is the first in the series to test on a real Android device using IL2CPP, so these numbers should be much more accurate for most games. Read on for the results!
Over a year ago I wrote an article title Do Foreach Loops Create Garbage using Unity 5.2 and tested foreach
with a variety of collections: List
, Dictionary
, arrays, etc. Since then Unity has a new C# compiler and version 5.6 has been released. Is it safe to use foreach
now? Read on to find out!
Say you need to keep track of things you’ve already done, perhaps to avoid doing them again. What’s the fastest way to do that? HashSet<T>
seems like a natural fit, so you might choose that without a second thought. But is it faster than similar collections like Hashtable
and Dictionary<TKey, TValue>
? Today’s article puts all three to the test to see which one can insert elements, check for containment, and remove elements the quickest. Read on for the surprising results!
Closures allow you to save the local variables of a function and access them later in a callback. Think of how lambdas can access the local variables of the function they’re declared in, even though the lambda itself is another function. Unfortunately, creating a lambda like this creates garbage for the GC to collect and you have no control over that process. Today’s article introduces an alternative that allows you to take control over the GC and still use nice, type-safe closures. Read on to learn how!
As you know, making your game data-driven is good idea. So you make all kinds of configuration files with numbers in them: starting health, damage amount, XP reward, etc. But what do you do when those values aren’t just constants? Today’s article presents a little one-file class that you can use to evaluate simple formulas instead of just constants. What if your data for “XP reward” wasn’t just “100” but instead a formula like “10+MMRDifference*50”? That’s a great tool you can hand to game designers to data-drive your game. Read on to learn how!