Posts Tagged function

Generic Algorithm Examples

Tags: , ,

There are many common algorithms that we use constantly: searching, filtering, mapping, and so forth. Today we’ll write a few in the Burst-friendly way as examples of how to write Burst-friendly code that’s still reusable and efficient.

Read the rest of this article »

4 Comments

Function Types: A Spectrum

Tags: , , , ,

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.

Read the rest of this article »

5 Comments

Burst Function Pointers vs. Jobs

Tags: , , ,

Function pointers aren’t the only way to express a unit of work. Unity’s own job system does just this, albeit in a different way. Today we’ll compare the performance of Burst’s function pointers against jobs themselves!

Read the rest of this article »

3 Comments

Burst Function Pointers vs. Switch Statements

Tags: , , ,

A couple weeks ago we took a look at the performance of function pointers in Burst. In doing so, we left out an alternative: good old switch statements. Today we’ll put those to the test to see how they stack up next to Burst’s newfangled function pointers!

Read the rest of this article »

4 Comments

DIY Virtual Functions in Burst

Tags: , , , , ,

Now that we’ve seen how function pointers work and perform in Burst, let’s use them to build a higher-level feature: virtual functions!

Read the rest of this article »

3 Comments

Burst Function Pointers Performance

Tags: , , ,

Last week we took a look at function pointers in Burst 1.2 and Unity 2019.3. Today we’ll continue looking into them by analyzing their performance.

Read the rest of this article »

4 Comments

Function Pointers in Burst

Tags: , ,

Unity 2019.3 and Burst 1.2 bring us support for function pointers! Behind the scenes, these power everyday C# functionality like virtual and abstract functions, delegates, and interfaces. Today we’ll look at how to use them and what Burst compiles them to.

Read the rest of this article »

1 Comment

IL2CPP Output for C# 7.3: Local functions, fixed, and stackalloc

Tags: , , , ,

Continuing the series, today we’ll dive into local functions, fixed-size buffers, fixed blocks on arbitrary types with GetPinnableReference, and stackalloc initializers to see how they’re all implemented in C++ and what assembly code ends up actually running on the CPU.

Read the rest of this article »

2 Comments

Garbage Gotchas

Tags: , , , , , , ,

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.

Read the rest of this article »

2 Comments

Delegates and Garbage Creation

Tags: , , , ,

Two facts are at odds in Unity programming. First, delegates like Action, Func, and EventHandler are extremely common with or without events. Second, the garbage collector is a huge source of CPU spikes and memory fragmentation in our games. Why are these facts at odds? Because code that uses delegates is almost always written in a way that creates garbage. It’s an extremely easy trap to fall into, but this article will show you how to get out of it!

Read the rest of this article »

12 Comments