Fixed-point types save memory compared to floating-point types, but can they also improve performance? Today’s article finds out!
Posts Tagged performance
Today we continue to explore how we can store values in less than a byte. We’ll expand the
BitStream struct with the capability to write values in addition to just reading them. Read on to see how to implement this functionality and for the full source code which you can use in your projects.
The smallest a C# type can be is one byte. The
byte type and and an empty struct are examples of this. But what if we want to store data in less than a byte to improve performance such as load times and CPU cache utilization? Today’s article does just this by packing at the bit level!
Floating-point math is fast these days, but fixed-point still has a purpose: we can use it to store real numbers in less than 32 bits. Saving a measly 16 or 24 bits off a
float might not sound appealing, but cutting the data size in half or quarter often does when multiplied across large amounts of real numbers. We can shrink downloads, improve load times, save memory, and fit more into the CPU’s data caches. So today we’ll look at storing numbers in fixed-point formats and see how easy it can be to shrink our data!
Bit fields give us the ability to use less than one byte to store an integer. This can be really useful to fit more data into a CPU cache or to reduce memory usage in general. Unfortunately, bit fields aren’t built into C#. Today we’ll work around that by creating our own!
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!
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!
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
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.
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!