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.
Posts Tagged string
As programmers, we concatenate strings all the time. Should we worry about the performance? How about the amount of garbage we’re producing for the garbage collector? Today’s article runs a quick test to find out!
What’s the fastest way to build a
string in C#? We have several options available to us.
string.Format() is a function built right in to the
string class., Concatenation (
"a" + "b") is a feature of the language itself! The
System.Text.StringBuilder class is a built in class with a name that makes it sound like it’s purpose-built for building strings. Today I pit these three against each other to find out just which one you should be using to build strings as quickly as possible.
Today’s article is the first to test Unity script performance speed. It establishes a way to set up and test C# scripts in Unity whether you have access to Pro or not. As a first example, I was reminded by the news this week that
AddComponent(string) is being removed in Unity 5.0. These alternative versions of
GetComponent aren’t something I normally use, but the news got me thinking of their performance compared to the generic-typed versions:
GetComponent<ComponentType>(). The docs say to avoid the versions taking a
string, but how bad could the performance really be? Today’s article puts the two versions to the test to find out just that!
When you instantiate one of your classes, how much memory does it use? Today’s article tries out a lot of combinations and counts the bytes used. The conclusion is easy to remember and will give you a solid understanding of how much memory your app is using.
When I first wrote about master strings I proposed a function that would help to trim them down and potentially save a lot of memory. However, that method still resulted in a string with a master string one longer than it. Ideally, we’d have no master string at all. Since then, three astute readers chimed in with alternate solutions to the problem. Today I put try all three out to see which method does the best job of cleaning master strings.
Pop quiz: what’s the difference between an
Object and a
Dictionary? If you said “
Dictionary can have non-
String keys”, you bought into a common myth. Today’s article shows the cases where the lowly
Object class will use non-
String keys whether you like it or not. Read on for the details.
I’ve recently been notified of a way to dramatically speed up
for-in loops. I’ve tested this method out and indeed there is a 5x speedup. Employing the technique is also really easy. Unfortunately, the speedup is sometimes an illusion. Read on to learn a little more about
for-in loops and how you could potentially speed yours up by 5x.