The series continues today with functions. These are obviously core to any programming language, but it’s not obvious how many ways they differ from functions in C#. From compile-time execution to automatic return value types, there are a lot of differences to cover today.
Posts Tagged static
Burst 1.2 comes with a new feature:
SharedStatic<T>. This allows us to write to static variables from within Burst-compiled code like jobs and function pointers. Today we’ll look at how this is implemented by Burst and IL2CPP. We’ll also put them to a performance test to see how fast they are.
C# gives us lots of types of functions for us to call. We must constantly decide between them. Should this function be
static? Should it be
virtual? There are many factors that go into making the decision. Today we’ll look at the function types as a spectrum and hopefully get a little perspective on our options.
I continue to learn a lot by reading the C++ code that IL2CPP outputs. Like reading decompiled code, it gives some insight into what what Unity’s build process is doing with the C# we give it. This week I learned that
sizeof(MyStruct) isn’t a compile-time constant like it is in C++. Because of that, IL2CPP generates some less-than-ideal C++ code every time you use it. Today’s article shows the process I went through to work around that issue and ends up with some code you can drop into your project to avoid the problem.
We code in C#, but that’s just a starting point. Our C# code is compiled to DLLs and then converted into C++ where it’s compiled again to machine code. The good news is that this isn’t a black box! I’ve recently been reading through the C++ code that IL2CPP outputs and learning quite a lot. Today’s article is about some of the surprises that I encountered and how you can change your C# code to avoid some nasty pitfalls.
By request, today’s article follows up on my Unity Function Performance article from a year and a half ago using Unity 5.0. It adds on
virtual functions to get a more complete picture of how various function calls in Unity perform. Of course it runs these tests using Unity 5.4 to see if there have been any changes in the engine. Read on for the results!
Which is the fastest kind of C# function in Unity? There are several to choose from: regular old instance methods, static methods, delegates, and lambdas. Is there any performance reason to choose one over the other? Today’s article answers just these questions by putting each type of function to the test. Read on to see which is fastest and which is slowest!
Today’s article is quick and to the point: when you need to take the base 10 logarithm of an integer you can speed this up by about 8x. Read on for the technique and save some CPU cycles!
Above all others, there is one article I refer back to most: 2009’s Function Performance. It was updated for Flash Player 10.1 and 10.2, but not 10.3, 11.0, 11.1, or 11.2. Today I’m updating this article for Flash Player 11.2, adding some missing function types, and including a set of graphs to make for the ultimate function performance reference.