Next-Level Code Generation

Tags: ,

About a year ago we saw how easy it is to use code generation to go beyond the limits of C# generics. The system we used simply replaced strings in a template file to generate a C# file. Today we’ll go way further and radically increase the power of the code generator by using some simple, off-the-shelf tools.

Read the rest of this article »

4 Comments

DIY Iterators and Coroutines

Tags: , , ,

Iterators aren’t magic. We’ve seen the IL2CPP output for them and it’s not complex. It turns out we can just as easily implement our own iterators and gain some nice advantages along the way. Read on to learn how!

Read the rest of this article »

No Comments

NotNull and Owner

Tags: , ,

The Guidelines Support Library is a small collection of utilities for C++. Today we’ll look at how two of them can make our C# code safer and cleaner.

Read the rest of this article »

2 Comments

NativeIntPtr and NativeLongPtr: Part 2

Tags: , , , ,

Last week’s article introduced two new native collection types: NativeIntPtr and NativeLongPtr. These were useful for both IJob and IJobParallelFor jobs, but performance was degraded in IJobParallelFor. Today we’ll remedy that, explore some more aspects of Unity’s native collection and job systems, and learn more about CPU caches along the way.

Read the rest of this article »

6 Comments

NativeIntPtr and NativeLongPtr

Tags: , ,

Today we’ll add two new types to the Native Collections suite: NativeIntPtr and NativeLongPtr. We’ll make them usable with both IJob and IJobParallelFor and explore some new features Unity’s native container system along the way.

Read the rest of this article »

4 Comments

The Effects of Useless Code

Tags: , , , ,

There are a lot of ways to write C# code that has no effect. One common way is to initialize class fields to their default values: public int Value = 0;. Today we’ll go over five types of useless code and see what effect it has on the actual machine code that the CPU executes. Do IL2CPP and the C++ compiler always do the right thing? Let’s find out!

Read the rest of this article »

No Comments

The Maybe Monad

Tags: , , ,

Monads sound fancy, but sometimes they’re actually really simple and useful. Today we’ll look at the Maybe monad, which is a low-overhead tool that’s extremely useful to prevent bugs.

Read the rest of this article »

12 Comments

C# Tasks vs. Unity Jobs

Tags: , , ,

Two weeks ago we tested the performance of the async and await keywords plus the C# Task system against Unity‚Äôs new C# jobs system. This tested the usual combination of async and await with the Task system, but didn’t test the Task system directly against Unity’s C# jobs system. Today we’ll test that and, in so doing, see how to use the Task system without the async and await keywords.

Read the rest of this article »

8 Comments

How Async and Await Work

Tags: , , , ,

Last week’s article tested the performance of the async and await keywords plus the C# Task system against Unity’s new C# jobs system. This week we’ll go in depth with async and await to learn how they work, how they relate to the Task system, and how we can customize them for our own uses.

Read the rest of this article »

1 Comment

Async & Await vs. Unity Jobs

Tags: , ,

Unity 2018.1 brought us two asynchronous code systems. First, there’s C# 5’s async and await keywords in conjunction with the Task and Task<T> types. Second, there’s Unity’s own C# jobs system. There are many differences, but which is faster? Today’s article puts them to the test to find out!

Read the rest of this article »

21 Comments