Posts Tagged performance

FastList: A Solution to List’s GC Problems?

Tags: ,

As we know, foreach loops create garbage when used with a List<T>. This happens the first time you iterate over one and it happens every time thereafter. A comment on that article shared a link to a class called FastList that was written expressly to solve the GC issue. Does it? How does its performance compare to plain old List? Today’s article puts it to the test to find out!

Read the rest of this article »

5 Comments

How Often Should You Force Garbage Collection?

Tags: , ,

One typical piece of advice for dealing with the slowness of Unity’s garbage collector is to periodically force a garbage collection, such as every 30 frames. Even Unity advises this. The idea is that you’ll spread out the garbage collection work across many frames rather than having a big spike that causes your frame rate to stutter. But the question remains- what’s the best rate to force the GC? Today’s article tries out various intervals to see which is best. Read on for the results!

Read the rest of this article »

1 Comment

Error Handling Performance

Tags: , , ,

Having just concluded the series on handling errors without using exceptions, now’s a good time to check up on an assertion I made in the first part: exceptions are slow. A good question to ask is “compared to what?” So let’s put them up against good old error codes and the new Either type I presented in the series. Which is fastest when there is no error? Which is fastest when there is an error? Read on to find out!

Read the rest of this article »

No Comments

Event Performance: C# vs. UnityEvent

Tags: , ,

Unity programmers have their choice of two kinds of events. We could use the built-in C# event keyword or Unity’s UnityEvent classes. Which is faster? Which one creates more garbage? Today’s article finds out!

Read the rest of this article »

45 Comments

Delegate() vs. Delegate.Invoke()

Tags: , ,

In reading others’ C# code I consistently see some programmers call delegates like a function—del()—and others use the Invoke method of the Delegate class: del.Invoke(). Is there any difference between the two? Is one better than the other? Today’s article finds out!

Read the rest of this article »

9 Comments

Using Structs to Avoid Creating Garbage

Tags: , , ,

It’s easy to forget about struct in C#. After all, it’s not available in other languages like Java or AS3 and it seems to have fewer features than good old class. But struct can really help you out when it comes to garbage creation! Today’s article discusses some strategies to get the most out of struct. Read on to learn how to use structs to put a stop to that pesky garbage collector!

Read the rest of this article »

8 Comments

Do Foreach Loops Create Garbage?

Tags: , , , , ,

We know that we should reduce the garbage our code produces to lighten the load on Unity’s garbage collector. The trouble is that many of the ways we’re creating garbage are hidden from us. One such way to inadvertently create a lot of garbage is to use a foreach loop… at least that’s what we’ve been told. Do foreach loops really create garbage for all types of arrays, lists, dictionaries, and the rest of the collections? Do they create garbage for every loop or just the first one? Today’s article investigates to put these questions to rest. Are you safe using foreach loops or should you re-write everything to use for. Read on to find out!

Read the rest of this article »

8 Comments

Too Many Coroutines: A Queue Solution

Tags: , , ,

Unity’s coroutine support is great. So great that it’s easy to go overboard and end up with too many of them. That could be for any number of reasons. Perhaps the coroutines are using too much memory or have too many files open at once. In any case, you’ll need to find a way to limit how many are running at a single time. Today’s article introduces a solution to the problem that queues coroutines so you never have too many running. Read on to learn about the solution and for the class that implements it.

Read the rest of this article »

19 Comments

String Concatenation Performance

Tags: , , ,

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!

Read the rest of this article »

No Comments

Encryption Algorithm Performance

Tags: ,

Last week I covered the performance of cryptographic hash algorithms like MD5 and SHA-1. This week I’ll continue by testing the performance of the closely-related encryption algorithms. This includes algorithms like AES, DES, RC2, Rijndael, and TripleDES. Which is fastest? Does the key size, block size, padding mode, or cipher mode matter? Read on to see!

Read the rest of this article »

2 Comments