Burst-Compiled Generic Algorithms

Tags: , , ,

Many algorithms get used over and over: searching, sorting, filtering, etc. C# makes these available with LINQ and functions like Array.Sort, but these can’t be compiled by Burst because interfaces and delegates aren’t supported. So how do we implement these generic algorithms to avoid re-writing them over and over? Today we’ll explore one technique to solve this problem. Read on to learn how!

Read the rest of this article »

3 Comments

Steal Some More Bits

Tags: , , ,

Today we continue stealing float bits, but in an entirely different way this time. We’ll end up with the ability to switch between float and 21-bit integer modes and to know which mode we’re in. We can do all of this without using any more than four bytes just by exploiting a little knowledge of the float data format. Read on to learn how!

Read the rest of this article »

No Comments

Optional<T>: A Nullable<T> Alternative

Tags: , , , , ,

Today we’ll make a new type that addresses some of the deficiencies in Nullable<T>. We’ll end up with a good tool for dealing with operations that may or may not produce a result or take a parameter, even in Burst-compiled code. Read on to see how it works!

Read the rest of this article »

2 Comments

Steal Some Bits

Tags: , ,

With a bit of understanding and some C# trickery, we can exploit how float works to cram in a few more bits and make some big performance gains. Today we’ll see how to steal some of the bits from a float!

Read the rest of this article »

No Comments

Math.Abs vs. Mathf.Abs vs. math.abs vs. Custom

Tags: , ,

A reader recently asked what the fastest way to take an absolute value was. It occurred to me that there are a lot of ways to do this in Unity! So today we’ll try them all out and see which is best.

Read the rest of this article »

7 Comments

NativeHashSet<T>

Tags: , , ,

Unity’s Native Collections package, currently in Preview, provides a hash map but not a hash set. Today we’ll supplement NativeHashMap<TKey, TValue> with our own NativeHashSet<T> as part of the NativeCollections repo. Read on for performance results and to see how to use it!

Read the rest of this article »

No Comments

The Virtue of Stopping

Tags: ,

What do you do when your code finds a bug? We write code to check for null references and out-of-bounds indexes all the time. What’s the proper way to respond when we find a problem? Today we’ll look at two options and see how they pan out.

Read the rest of this article »

8 Comments

P/Invoke in Burst: No Safety Net

Tags: , ,

Calling into native code like C++ from C# is a powerful interoperability tool in Unity. As we move more and more code out of Mono and IL2CPP and into Burst, will we still have this tool available? Today we’ll find out!

Read the rest of this article »

4 Comments

Tuples in Burst

Tags: , ,

Tuples are a new feature in C# 7 and they’re backed by the ValueTuple struct, not class. Hopefully they’ll be supported by Burst, so let’s try them out!

Read the rest of this article »

3 Comments

How Burst Compiles Switches and Ref Parameters

Tags: , ,

Today we go back to basics and see how Burst compiles some fundamental language features: switch statements and ref parameters… with surprising results!

Read the rest of this article »

No Comments