Steal Some Bits

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 »

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

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 »

NativeHashSet<T>

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 »

The Virtue of Stopping

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 »

P/Invoke in Burst: No Safety Net

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 »

Tuples in Burst

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 »

How Burst Compiles Switches and Ref Parameters

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 »

Force Method Inlining in Burst

Burst 1.0.1 is a patch-level update to the original 1.0.0 release, but it actually contains a useful new feature: we’re now able to force methods to be inlined. Read on to see how!

Read the rest of this article »

Adding Unions to Burst

We’ve seen how to add unions to C#, but does this work with the new Burst compiler? Today we’ll put it to the test and see if it can handle some of the more advanced struct customization features in C#!

Read the rest of this article »

Assertions in Burst

Assertions are an incredibly handy tool, but do they work in Burst-compiled jobs? Today we’ll find out!

Read the rest of this article »