While little utilized, C#’s
struct type can come in really handy sometimes. Today’s article shows how to use it to get a lot more mileage out of modern CPUs’ caches to really boost your app’s performance. Read on for some quick tips!
While little utilized, C#’s
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!
At first glance an
Updater class seems unnecessary in Unity. All you have to do is inherit from
MonoBehaviour and add an
Update function. But what if you don’t want to inherit from
Updater, an easy way to still get an update event and cut your dependency on
MonoBehaviour. This works great for code in DLLs, “pure code” projects, or just projects that don’t want to put everything into
MonoBehaviours. Read on for the source code and how to use it!
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!
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!
Last week’s article introduced the
Either class as an alternative to exceptions that makes it easy for functions to declare their error results in addition to their success results and for callers of those functions to handle both results. Today we’ll go further by linking together multiple functions to handle all the error cases almost transparently. Read on to learn how to make the most out of
Exceptions are the de facto way to handle errors in C#, but they have problems. Callers don’t know if the function they’re calling will throw an exception at all or which types of exceptions it’ll throw. Exceptions also introduce an alternative control flow that’s often hard for programmers to follow. They make our code slower too, even when never thrown! Today’s article introduces an alternative to exceptions to help solve all of these issues. Read on to learn a new way to handle errors!
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!
In today’s article I’ll share a technique that can help you reason about your classes (and structs). The core idea is to move some methods out of the class into helper functions. Doing this can really simplify the class and simplify the functions so they’re much more easily understood by readers (including yourself!), more easily written, and more easily extended. Read on to learn more about this technique!